Skip to content

Commit

Permalink
fix: default to all targets when using --edition flags in cargo fix
Browse files Browse the repository at this point in the history
Signed-off-by: Rustin170506 <[email protected]>
  • Loading branch information
Rustin170506 committed Mar 6, 2025
1 parent 69f398f commit a9f92ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/bin/cargo/commands/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {

let mut opts = args.compile_options(gctx, mode, Some(&ws), ProfileChecking::LegacyTestOnly)?;

if !opts.filter.is_specific() {
// cargo fix with no target selection implies `--all-targets`.
let edition = args.flag("edition") || args.flag("edition-idioms");
if !opts.filter.is_specific() && edition {
// When `cargo fix` is run without specifying targets but with `--edition` or `--edition-idioms`,
// it should default to fixing all targets.
// See: https://github.com/rust-lang/cargo/issues/13527
opts.filter = ops::CompileFilter::new_all_targets();
}

Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ fn does_not_warn_about_dirty_ignored_files() {
}

#[cargo_test]
fn fix_all_targets_by_default() {
fn do_not_fix_tests() {
let p = project()
.file("src/lib.rs", "pub fn foo() { let mut x = 3; let _ = x; }")
.file("tests/foo.rs", "pub fn foo() { let mut x = 3; let _ = x; }")
Expand All @@ -814,7 +814,7 @@ fn fix_all_targets_by_default() {
.env("__CARGO_FIX_YOLO", "1")
.run();
assert!(!p.read_file("src/lib.rs").contains("let mut x"));
assert!(!p.read_file("tests/foo.rs").contains("let mut x"));
assert!(p.read_file("tests/foo.rs").contains("let mut x"));
}

#[cargo_test]
Expand Down Expand Up @@ -1424,7 +1424,7 @@ fn fix_to_broken_code() {
p.cargo("build").cwd("foo").run();

// Attempt to fix code, but our shim will always fail the second compile
p.cargo("fix --allow-no-vcs --broken-code")
p.cargo("fix --all-targets --allow-no-vcs --broken-code")
.cwd("bar")
.env("RUSTC", p.root().join("foo/target/debug/foo"))
.with_status(101)
Expand Down

0 comments on commit a9f92ed

Please sign in to comment.