Skip to content

Fix rustfmt relative custom command#22010

Merged
Veykril merged 1 commit intorust-lang:masterfrom
erfanio:rustfmt-fix
Apr 11, 2026
Merged

Fix rustfmt relative custom command#22010
Veykril merged 1 commit intorust-lang:masterfrom
erfanio:rustfmt-fix

Conversation

@erfanio
Copy link
Copy Markdown
Contributor

@erfanio erfanio commented Apr 10, 2026

When rustfmt.overrideCommand is a relative path, it's joined with the workspace root to make it an absolute path. Without this the command path can't be resolved, especially because rustfmt changes the cwd to make sure rustfmt.toml works correctly.

Currently run_rustfmt only does this when it finds a target_spec using target_spec_for_file which only works for the root file of the target.

This commit changes it to use TargetSpec::for_file which works for any file in the crate.

When `rustfmt.overrideCommand` is a relative path, it's joined with the
workspace root to make it an absolute path. Without this the command
path can't be resolved, especially because rustfmt changes the cwd to
make sure rustfmt.toml works correctly.

Currently `run_rustfmt` only does this when it finds a `target_spec`
using `target_spec_for_file` which only works for the root file of the
target.

This commit changes it to use `TargetSpec::from_file` which works for
any file in the crate.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 10, 2026
@erfanio
Copy link
Copy Markdown
Contributor Author

erfanio commented Apr 11, 2026

Looking at this code path a bit closer, I actually think maybe we don't need to find the target_spec at all. The code path tries to find a sensible root even if the file is not part of any target, so limiting formatting to files that are part of a target feel unnecessary here. See erfanio@abd932c0bb

Copy link
Copy Markdown
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

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

@Veykril Veykril added this pull request to the merge queue Apr 11, 2026
Merged via the queue into rust-lang:master with commit 55825a4 Apr 11, 2026
31 of 33 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants