diff --git a/tests/testsuite/rustc.rs b/tests/testsuite/rustc.rs index be01f1465..d3718686a 100644 --- a/tests/testsuite/rustc.rs +++ b/tests/testsuite/rustc.rs @@ -795,3 +795,67 @@ windows ) .run(); } + +#[cargo_test] +fn precedence() { + // Ensure that the precedence of cargo-rustc is only lower than RUSTFLAGS, + // but higher than most flags set by cargo. + // + // See rust-lang/cargo#14346 + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + edition = "2021" + + [lints.rust] + unexpected_cfgs = "allow" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("rustc --release -v -- --cfg cargo_rustc -C strip=symbols") + .env("RUSTFLAGS", "--cfg from_rustflags") + .with_stderr_data( + str![[r#" +[COMPILING] foo v0.0.0 ([ROOT]/foo) +[RUNNING] `rustc [..]--cfg cargo_rustc -C strip=symbols [..]-C strip=debuginfo [..]--cfg from_rustflags` +[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s + +"#]] + ) + .run(); + + // Ensure the short-live env var to work + p.cargo("clean").run(); + p.cargo("rustc --release -v -- --cfg cargo_rustc -C strip=symbols") + .env("RUSTFLAGS", "--cfg from_rustflags") + .env("__CARGO_RUSTC_ORIG_ARGS_PRIO", "1") + .masquerade_as_nightly_cargo(&["cargo-rustc-precedence"]) + .with_stderr_data( + str![[r#" +[COMPILING] foo v0.0.0 ([ROOT]/foo) +[RUNNING] `rustc [..]--cfg cargo_rustc -C strip=symbols [..]-C strip=debuginfo [..]--cfg from_rustflags` +[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s + +"#]] + ) + .run(); + + // Ensure non-nightly to work as before + p.cargo("clean").run(); + p.cargo("rustc --release -v -- --cfg cargo_rustc -C strip=symbols") + .env("RUSTFLAGS", "--cfg from_rustflags") + .with_stderr_data( + str![[r#" +[COMPILING] foo v0.0.0 ([ROOT]/foo) +[RUNNING] `rustc [..]--cfg cargo_rustc -C strip=symbols [..]-C strip=debuginfo [..]--cfg from_rustflags` +[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s + +"#]] + ) + .run(); +}