Skip to content

Fixed ICE when formatting files outside of toml dir#6844

Open
aznszn wants to merge 1 commit intorust-lang:mainfrom
aznszn:fix/panic-when-formatting-outside-toml-dir
Open

Fixed ICE when formatting files outside of toml dir#6844
aznszn wants to merge 1 commit intorust-lang:mainfrom
aznszn:fix/panic-when-formatting-outside-toml-dir

Conversation

@aznszn
Copy link
Copy Markdown
Contributor

@aznszn aznszn commented Mar 26, 2026

Fixes: #6843

The panic was happening due to a line in the ignore crate:

assert!(!path.has_root(), "path is expected to be under the root");

Fix

  • Added a guard that returns false when checking if a file matches an ignore pattern, if the ignore rule's directory is not an ancestor of the file's absolute path.
  • Added a regression test

N.b.: This assumes that rustfmt ignore rules are supposed to be for that directory and below

@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Mar 26, 2026
@aznszn aznszn force-pushed the fix/panic-when-formatting-outside-toml-dir branch from 5feba42 to 0cb0339 Compare March 26, 2026 12:24
@aznszn
Copy link
Copy Markdown
Contributor Author

aznszn commented Mar 29, 2026

i will fix the CI soon

@jieyouxu jieyouxu added S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels Mar 30, 2026
@aznszn aznszn force-pushed the fix/panic-when-formatting-outside-toml-dir branch from 0cb0339 to 12c3acd Compare March 30, 2026 08:16
@aznszn
Copy link
Copy Markdown
Contributor Author

aznszn commented Mar 30, 2026

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. labels Mar 30, 2026
Comment on lines +26 to +27
if p.is_absolute() && !p.starts_with(self.ignore_set.path()) {
false
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the underlying bug is: someone tried to invoke rustfmt with a --config-path that is outside the tree, then

  • Before: we panic
  • Now: we silently ignore it, since is_match always returns false here

I'm wondering if instead we could do one of:

  • Print an error to the user, telling them that the config path isn't valid
  • Try to make sense of it: is there anything we could reasonably do here? If we're running in cargo fmt could we instead use the path to Cargo.toml as the root of ignores?

It doesn't help that --config-path is a bit confusing #5206

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE when running cargo fmt -- --config-path ../foo/bar.toml with unstable ignore feature

4 participants