diff --git a/src/cargo/ops/fix.rs b/src/cargo/ops/fix.rs index 1dd4ee8ca80..2e09303a1ac 100644 --- a/src/cargo/ops/fix.rs +++ b/src/cargo/ops/fix.rs @@ -165,7 +165,7 @@ pub fn fix_maybe_exec_rustc() -> CargoResult { // not the best heuristic but matches what Cargo does today at least. let mut fixes = FixedCrate::default(); if let Some(path) = &args.file { - if env::var("CARGO_PRIMARY_PACKAGE").is_ok() { + if args.primary_package { trace!("start rustfixing {:?}", path); fixes = rustfix_crate(&lock_addr, rustc.as_ref(), path, &args)?; } @@ -503,6 +503,7 @@ struct FixArgs { idioms: bool, enabled_edition: Option, other: Vec, + primary_package: bool, } enum PrepareFor { @@ -543,6 +544,7 @@ impl FixArgs { ret.prepare_for_edition = PrepareFor::Next; } ret.idioms = env::var(IDIOMS_ENV).is_ok(); + ret.primary_package = env::var("CARGO_PRIMARY_PACKAGE").is_ok(); ret } @@ -554,12 +556,14 @@ impl FixArgs { .arg("--cap-lints=warn"); if let Some(edition) = &self.enabled_edition { cmd.arg("--edition").arg(edition); - if self.idioms { + if self.idioms && self.primary_package { if edition == "2018" { cmd.arg("-Wrust-2018-idioms"); } } } - if let Some(edition) = self.prepare_for_edition_resolve() { - cmd.arg("-W").arg(format!("rust-{}-compatibility", edition)); + if self.primary_package { + if let Some(edition) = self.prepare_for_edition_resolve() { + cmd.arg("-W").arg(format!("rust-{}-compatibility", edition)); + } } } diff --git a/tests/testsuite/fix.rs b/tests/testsuite/fix.rs index dbf1035d8db..d37688368f0 100644 --- a/tests/testsuite/fix.rs +++ b/tests/testsuite/fix.rs @@ -1072,3 +1072,47 @@ fn does_not_crash_with_rustc_wrapper() { .env("RUSTC_WRAPPER", "/usr/bin/env") .run(); } + +#[test] +fn only_warn_for_relevant_crates() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + + [dependencies] + a = { path = 'a' } + "#, + ) + .file("src/lib.rs", "") + .file( + "a/Cargo.toml", + r#" + [package] + name = "a" + version = "0.1.0" + "#, + ) + .file( + "a/src/lib.rs", + " + pub fn foo() {} + pub mod bar { + use foo; + pub fn baz() { foo() } + } + ", + ) + .build(); + + p.cargo("fix --allow-no-vcs --edition") + .with_stderr("\ +[CHECKING] a v0.1.0 ([..]) +[CHECKING] foo v0.1.0 ([..]) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +") + .run(); +}