Skip to content

Commit ea31b4c

Browse files
committed
fix(cargo-rustc): stabilize higher precedence trailing flags
This was always enabled on nightly since 1.83-nightly (2024-09). We have no feedback since then, so assume it is a low-impact change. This stabilization is targeted at 1.85 (2025-02-20)
1 parent a4a3651 commit ea31b4c

File tree

2 files changed

+4
-66
lines changed

2 files changed

+4
-66
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -696,10 +696,8 @@ fn prepare_rustc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResult
696696
base.inherit_jobserver(&build_runner.jobserver);
697697
build_deps_args(&mut base, build_runner, unit)?;
698698
add_cap_lints(build_runner.bcx, unit, &mut base);
699-
if cargo_rustc_higher_args_precedence(build_runner) {
700-
if let Some(args) = build_runner.bcx.extra_args_for(unit) {
701-
base.args(args);
702-
}
699+
if let Some(args) = build_runner.bcx.extra_args_for(unit) {
700+
base.args(args);
703701
}
704702
base.args(&unit.rustflags);
705703
if build_runner.bcx.gctx.cli_unstable().binary_dep_depinfo {
@@ -754,12 +752,6 @@ fn prepare_rustdoc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResu
754752

755753
rustdoc.args(unit.pkg.manifest().lint_rustflags());
756754

757-
if !cargo_rustc_higher_args_precedence(build_runner) {
758-
if let Some(args) = build_runner.bcx.extra_args_for(unit) {
759-
rustdoc.args(args);
760-
}
761-
}
762-
763755
let metadata = build_runner.metadata_for_doc_units[unit];
764756
rustdoc
765757
.arg("-C")
@@ -800,10 +792,8 @@ fn prepare_rustdoc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResu
800792

801793
rustdoc::add_output_format(build_runner, unit, &mut rustdoc)?;
802794

803-
if cargo_rustc_higher_args_precedence(build_runner) {
804-
if let Some(args) = build_runner.bcx.extra_args_for(unit) {
805-
rustdoc.args(args);
806-
}
795+
if let Some(args) = build_runner.bcx.extra_args_for(unit) {
796+
rustdoc.args(args);
807797
}
808798
rustdoc.args(&unit.rustdocflags);
809799

@@ -1107,11 +1097,6 @@ fn build_base_args(
11071097

11081098
cmd.args(unit.pkg.manifest().lint_rustflags());
11091099
cmd.args(&profile_rustflags);
1110-
if !cargo_rustc_higher_args_precedence(build_runner) {
1111-
if let Some(args) = build_runner.bcx.extra_args_for(unit) {
1112-
cmd.args(args);
1113-
}
1114-
}
11151100

11161101
// `-C overflow-checks` is implied by the setting of `-C debug-assertions`,
11171102
// so we only need to provide `-C overflow-checks` if it differs from
@@ -2001,19 +1986,3 @@ fn scrape_output_path(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoR
20011986
.outputs(unit)
20021987
.map(|outputs| outputs[0].path.clone())
20031988
}
2004-
2005-
/// Provides a way to change the precedence of `cargo rustc -- <flags>`.
2006-
///
2007-
/// This is intended to be a short-live function.
2008-
///
2009-
/// See <https://github.com/rust-lang/cargo/issues/14346>
2010-
fn cargo_rustc_higher_args_precedence(build_runner: &BuildRunner<'_, '_>) -> bool {
2011-
build_runner.bcx.gctx.nightly_features_allowed
2012-
&& build_runner
2013-
.bcx
2014-
.gctx
2015-
.get_env("__CARGO_RUSTC_ORIG_ARGS_PRIO")
2016-
.ok()
2017-
.as_deref()
2018-
!= Some("1")
2019-
}

tests/testsuite/rustc.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -817,42 +817,11 @@ fn precedence() {
817817

818818
p.cargo("rustc --release -v -- --cfg cargo_rustc -C strip=symbols")
819819
.env("RUSTFLAGS", "--cfg from_rustflags")
820-
.masquerade_as_nightly_cargo(&["cargo-rustc-precedence"])
821820
.with_stderr_data(str![[r#"
822821
[COMPILING] foo v0.0.0 ([ROOT]/foo)
823822
[RUNNING] `rustc [..]-C strip=debuginfo [..]--cfg cargo_rustc -C strip=symbols --cfg from_rustflags`
824823
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
825824
826825
"#]])
827826
.run();
828-
829-
// Ensure the short-live env var to work
830-
p.cargo("clean").run();
831-
p.cargo("rustc --release -v -- --cfg cargo_rustc -C strip=symbols")
832-
.env("RUSTFLAGS", "--cfg from_rustflags")
833-
.env("__CARGO_RUSTC_ORIG_ARGS_PRIO", "1")
834-
.masquerade_as_nightly_cargo(&["cargo-rustc-precedence"])
835-
.with_stderr_data(
836-
str![[r#"
837-
[COMPILING] foo v0.0.0 ([ROOT]/foo)
838-
[RUNNING] `rustc [..]--cfg cargo_rustc -C strip=symbols [..]-C strip=debuginfo [..]--cfg from_rustflags`
839-
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
840-
841-
"#]]
842-
)
843-
.run();
844-
845-
// Ensure non-nightly to work as before
846-
p.cargo("clean").run();
847-
p.cargo("rustc --release -v -- --cfg cargo_rustc -C strip=symbols")
848-
.env("RUSTFLAGS", "--cfg from_rustflags")
849-
.with_stderr_data(
850-
str![[r#"
851-
[COMPILING] foo v0.0.0 ([ROOT]/foo)
852-
[RUNNING] `rustc [..]--cfg cargo_rustc -C strip=symbols [..]-C strip=debuginfo [..]--cfg from_rustflags`
853-
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
854-
855-
"#]]
856-
)
857-
.run();
858827
}

0 commit comments

Comments
 (0)