Skip to content

Commit 1d74d95

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 99dff6d commit 1d74d95

File tree

3 files changed

+16
-78
lines changed

3 files changed

+16
-78
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
@@ -2007,19 +1992,3 @@ fn scrape_output_path(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoR
20071992
.outputs(unit)
20081993
.map(|outputs| outputs[0].path.clone())
20091994
}
2010-
2011-
/// Provides a way to change the precedence of `cargo rustc -- <flags>`.
2012-
///
2013-
/// This is intended to be a short-live function.
2014-
///
2015-
/// See <https://github.com/rust-lang/cargo/issues/14346>
2016-
fn cargo_rustc_higher_args_precedence(build_runner: &BuildRunner<'_, '_>) -> bool {
2017-
build_runner.bcx.gctx.nightly_features_allowed
2018-
&& build_runner
2019-
.bcx
2020-
.gctx
2021-
.get_env("__CARGO_RUSTC_ORIG_ARGS_PRIO")
2022-
.ok()
2023-
.as_deref()
2024-
!= Some("1")
2025-
}

tests/testsuite/rustc.rs

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn lib() {
2828
p.cargo("rustc --lib -v -- -C debug-assertions=off")
2929
.with_stderr_data(str![[r#"
3030
[COMPILING] foo v0.0.1 ([ROOT]/foo)
31-
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C debuginfo=2 [..]-C debug-assertions=off[..]-C metadata=[..] [..]--out-dir [ROOT]/foo/target/debug/deps -L dependency=[ROOT]/foo/target/debug/deps`
31+
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C debuginfo=2 [..]-C metadata=[..] [..]--out-dir [ROOT]/foo/target/debug/deps -L dependency=[ROOT]/foo/target/debug/deps[..]-C debug-assertions=off[..]`
3232
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3333
3434
"#]])
@@ -46,7 +46,7 @@ fn build_main_and_allow_unstable_options() {
4646
.with_stderr_data(str![[r#"
4747
[COMPILING] foo v0.0.1 ([ROOT]/foo)
4848
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C debuginfo=2 [..]-C metadata=[..] --out-dir [ROOT]/foo/target/debug/deps -L dependency=[ROOT]/foo/target/debug/deps`
49-
[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--crate-type bin --emit=[..]link[..]-C debuginfo=2 [..]-C debug-assertions[..]-C metadata=[..] --out-dir [ROOT]/foo/target/debug/deps -L dependency=[ROOT]/foo/target/debug/deps --extern foo=[ROOT]/foo/target/debug/deps/libfoo-[HASH].rlib`
49+
[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--crate-type bin --emit=[..]link[..]-C debuginfo=2 [..]-C metadata=[..] --out-dir [ROOT]/foo/target/debug/deps -L dependency=[ROOT]/foo/target/debug/deps --extern foo=[ROOT]/foo/target/debug/deps/libfoo-[HASH].rlib[..]-C debug-assertions[..]`
5050
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
5151
5252
"#]])
@@ -83,7 +83,7 @@ fn build_with_args_to_one_of_multiple_binaries() {
8383
.with_stderr_data(str![[r#"
8484
[COMPILING] foo v0.0.1 ([ROOT]/foo)
8585
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C debuginfo=2 [..]-C metadata=[..] --out-dir [..]`
86-
[RUNNING] `rustc --crate-name bar --edition=2015 src/bin/bar.rs [..]--crate-type bin --emit=[..]link[..]-C debuginfo=2 [..]-C debug-assertions [..]`
86+
[RUNNING] `rustc --crate-name bar --edition=2015 src/bin/bar.rs [..]--crate-type bin --emit=[..]link[..]-C debuginfo=2 [..]-C debug-assertions[..]`
8787
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
8888
8989
"#]])
@@ -358,7 +358,7 @@ fn build_with_args_to_one_of_multiple_tests() {
358358
.with_stderr_data(str![[r#"
359359
[COMPILING] foo v0.0.1 ([ROOT]/foo)
360360
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C debuginfo=2 [..]-C metadata=[..] --out-dir [..]`
361-
[RUNNING] `rustc --crate-name bar --edition=2015 tests/bar.rs [..]--emit=[..]link[..]-C debuginfo=2 [..]-C debug-assertions --test[..]`
361+
[RUNNING] `rustc --crate-name bar --edition=2015 tests/bar.rs [..]--emit=[..]link[..]-C debuginfo=2 [..]--test[..]-C debug-assertions[..]`
362362
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
363363
364364
"#]])
@@ -395,7 +395,7 @@ fn build_foo_with_bar_dependency() {
395395
[COMPILING] bar v0.1.0 ([ROOT]/bar)
396396
[RUNNING] `rustc --crate-name bar [..] -C debuginfo=2[..]`
397397
[COMPILING] foo v0.0.1 ([ROOT]/foo)
398-
[RUNNING] `rustc --crate-name foo [..] -C debuginfo=2 [..]-C debug-assertions [..]`
398+
[RUNNING] `rustc --crate-name foo [..] -C debuginfo=2 [..]-C debug-assertions[..]`
399399
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
400400
401401
"#]])
@@ -430,7 +430,7 @@ fn build_only_bar_dependency() {
430430
.with_stderr_data(str![[r#"
431431
[LOCKING] 1 package to latest compatible version
432432
[COMPILING] bar v0.1.0 ([ROOT]/bar)
433-
[RUNNING] `rustc --crate-name bar [..]--crate-type lib [..] -C debug-assertions [..]`
433+
[RUNNING] `rustc --crate-name bar [..]--crate-type lib [..] -C debug-assertions[..]`
434434
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
435435
436436
"#]])
@@ -599,7 +599,7 @@ fn rustc_fingerprint() {
599599
p.cargo("rustc -v -- -C debug-assertions")
600600
.with_stderr_data(str![[r#"
601601
[COMPILING] foo v0.5.0 ([ROOT]/foo)
602-
[RUNNING] `rustc --crate-name foo [..]-C debug-assertions [..]`
602+
[RUNNING] `rustc --crate-name foo [..]-C debug-assertions[..]`
603603
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
604604
605605
"#]])
@@ -657,7 +657,7 @@ fn rustc_test_with_implicit_bin() {
657657
.with_stderr_data(
658658
str![[r#"
659659
[COMPILING] foo v0.5.0 ([ROOT]/foo)
660-
[RUNNING] `rustc --crate-name test1 --edition=2015 tests/test1.rs [..] --cfg foo [..]`
660+
[RUNNING] `rustc --crate-name test1 --edition=2015 tests/test1.rs [..] --cfg foo[..]`
661661
[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]`
662662
...
663663
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -816,42 +816,11 @@ fn precedence() {
816816

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

tests/testsuite/rustdoc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn rustdoc_args() {
106106
p.cargo("rustdoc -v -- --cfg=foo")
107107
.with_stderr_data(str![[r#"
108108
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
109-
[RUNNING] `rustdoc [..] --crate-name foo src/lib.rs -o [ROOT]/foo/target/doc [..] --cfg=foo -C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps [..]`
109+
[RUNNING] `rustdoc [..] --crate-name foo src/lib.rs -o [ROOT]/foo/target/doc [..]-C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps [..]--cfg=foo[..]`
110110
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
111111
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
112112
@@ -159,7 +159,7 @@ fn rustdoc_foo_with_bar_dependency() {
159159
[CHECKING] bar v0.0.1 ([ROOT]/bar)
160160
[RUNNING] `rustc [..] [ROOT]/bar/src/lib.rs [..]`
161161
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
162-
[RUNNING] `rustdoc [..] --crate-name foo src/lib.rs -o [ROOT]/foo/target/doc [..] --cfg=foo -C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps --extern [..]`
162+
[RUNNING] `rustdoc [..] --crate-name foo src/lib.rs -o [ROOT]/foo/target/doc [..]-C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps --extern [..]--cfg=foo[..]`
163163
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
164164
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
165165
@@ -195,7 +195,7 @@ fn rustdoc_only_bar_dependency() {
195195
.with_stderr_data(str![[r#"
196196
[LOCKING] 1 package to latest compatible version
197197
[DOCUMENTING] bar v0.0.1 ([ROOT]/bar)
198-
[RUNNING] `rustdoc [..] --crate-name bar [ROOT]/bar/src/lib.rs -o [ROOT]/foo/target/doc [..] --cfg=foo -C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps [..]`
198+
[RUNNING] `rustdoc [..] --crate-name bar [ROOT]/bar/src/lib.rs -o [ROOT]/foo/target/doc [..]-C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps [..]--cfg=foo[..]`
199199
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
200200
[GENERATED] [ROOT]/foo/target/doc/bar/index.html
201201
@@ -213,7 +213,7 @@ fn rustdoc_same_name_documents_lib() {
213213
p.cargo("rustdoc -v -- --cfg=foo")
214214
.with_stderr_data(str![[r#"
215215
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
216-
[RUNNING] `rustdoc [..] --crate-name foo src/lib.rs -o [ROOT]/foo/target/doc [..] --cfg=foo -C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps [..]`
216+
[RUNNING] `rustdoc [..] --crate-name foo src/lib.rs -o [ROOT]/foo/target/doc [..]-C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps [..]--cfg=foo[..]`
217217
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
218218
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
219219

0 commit comments

Comments
 (0)