Skip to content

Commit 5a5ee9a

Browse files
committed
Auto merge of #13499 - epage:always-edition, r=weihanglo
fix(rustc): Always pass --edition to rustc On [Internals](https://internals.rust-lang.org/t/idea-rustc-cargo-should-warn-on-unspecified-edition/20309), the idea came up for warning on unset Edition. I am working on the cargo warning but if rustc ever wants to do so, they'd be blocked on cargo ensuring `--edition` is always set. Hence this change.
2 parents a3ba4ee + 831847e commit 5a5ee9a

22 files changed

+299
-288
lines changed

src/cargo/core/features.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,7 @@ impl Edition {
256256
/// Updates the given [`ProcessBuilder`] to include the appropriate flags
257257
/// for setting the edition.
258258
pub(crate) fn cmd_edition_arg(&self, cmd: &mut ProcessBuilder) {
259-
if *self != Edition::Edition2015 {
260-
cmd.arg(format!("--edition={}", self));
261-
}
259+
cmd.arg(format!("--edition={}", self));
262260
if !self.is_stable() {
263261
cmd.arg("-Z").arg("unstable-options");
264262
}

tests/testsuite/artifact_dep.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,16 +1057,16 @@ fn build_script_deps_adopt_specified_target_unconditionally() {
10571057
p.cargo("check -v -Z bindeps")
10581058
.masquerade_as_nightly_cargo(&["bindeps"])
10591059
.with_stderr_does_not_contain(format!(
1060-
"[RUNNING] `rustc --crate-name build_script_build build.rs [..]--target {} [..]",
1060+
"[RUNNING] `rustc --crate-name build_script_build --edition=2015 build.rs [..]--target {} [..]",
10611061
target
10621062
))
1063-
.with_stderr_contains("[RUNNING] `rustc --crate-name build_script_build build.rs [..]")
1063+
.with_stderr_contains("[RUNNING] `rustc --crate-name build_script_build --edition=2015 build.rs [..]")
10641064
.with_stderr_contains(format!(
1065-
"[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--target {} [..]",
1065+
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]--target {} [..]",
10661066
target
10671067
))
10681068
.with_stderr_contains(format!(
1069-
"[RUNNING] `rustc --crate-name bar bar/src/main.rs [..]--target {} [..]",
1069+
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..]--target {} [..]",
10701070
target
10711071
))
10721072
.with_stderr_does_not_contain(format!(
@@ -1172,11 +1172,11 @@ fn non_build_script_deps_adopt_specified_target_unconditionally() {
11721172
p.cargo("check -v -Z bindeps")
11731173
.masquerade_as_nightly_cargo(&["bindeps"])
11741174
.with_stderr_contains(format!(
1175-
"[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--target {} [..]",
1175+
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]--target {} [..]",
11761176
target
11771177
))
11781178
.with_stderr_contains(format!(
1179-
"[RUNNING] `rustc --crate-name bar bar/src/main.rs [..]--target {} [..]",
1179+
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..]--target {} [..]",
11801180
target
11811181
))
11821182
.with_stderr_does_not_contain(format!(
@@ -1251,8 +1251,8 @@ fn no_cross_doctests_works_with_artifacts() {
12511251
.masquerade_as_nightly_cargo(&["bindeps"])
12521252
.with_stderr_contains(format!(
12531253
"[COMPILING] bar v0.5.0 ([CWD]/bar)
1254-
[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--target {triple} [..]
1255-
[RUNNING] `rustc --crate-name bar bar/src/main.rs [..]--target {triple} [..]
1254+
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]--target {triple} [..]
1255+
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..]--target {triple} [..]
12561256
[COMPILING] foo v0.0.1 ([CWD])
12571257
[RUNNING] `rustc --crate-name foo [..]
12581258
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..]",
@@ -1315,16 +1315,16 @@ fn build_script_deps_adopts_target_platform_if_target_equals_target() {
13151315
.arg(alternate_target)
13161316
.masquerade_as_nightly_cargo(&["bindeps"])
13171317
.with_stderr_does_not_contain(format!(
1318-
"[RUNNING] `rustc --crate-name build_script_build build.rs [..]--target {} [..]",
1318+
"[RUNNING] `rustc --crate-name build_script_build --edition=2015 build.rs [..]--target {} [..]",
13191319
alternate_target
13201320
))
1321-
.with_stderr_contains("[RUNNING] `rustc --crate-name build_script_build build.rs [..]")
1321+
.with_stderr_contains("[RUNNING] `rustc --crate-name build_script_build --edition=2015 build.rs [..]")
13221322
.with_stderr_contains(format!(
1323-
"[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--target {} [..]",
1323+
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]--target {} [..]",
13241324
alternate_target
13251325
))
13261326
.with_stderr_contains(format!(
1327-
"[RUNNING] `rustc --crate-name bar bar/src/main.rs [..]--target {} [..]",
1327+
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..]--target {} [..]",
13281328
alternate_target
13291329
))
13301330
.with_stderr_contains(format!(
@@ -1373,16 +1373,16 @@ fn profile_override_basic() {
13731373
"[RUNNING] `rustc --crate-name build_script_build [..] -C opt-level=1 [..]`",
13741374
)
13751375
.with_stderr_contains(
1376-
"[RUNNING] `rustc --crate-name bar bar/src/main.rs [..] -C opt-level=3 [..]`",
1376+
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..] -C opt-level=3 [..]`",
13771377
)
13781378
.with_stderr_contains(
1379-
"[RUNNING] `rustc --crate-name bar bar/src/main.rs [..] -C opt-level=1 [..]`",
1379+
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..] -C opt-level=1 [..]`",
13801380
)
13811381
.with_stderr_contains(
1382-
"[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..] -C opt-level=1 [..]`",
1382+
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..] -C opt-level=1 [..]`",
13831383
)
13841384
.with_stderr_contains(
1385-
"[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..] -C opt-level=3 [..]`",
1385+
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..] -C opt-level=3 [..]`",
13861386
)
13871387
.with_stderr_contains("[RUNNING] `rustc --crate-name foo [..] -C opt-level=3 [..]`")
13881388
.run();
@@ -2567,10 +2567,10 @@ fn with_assumed_host_target_and_optional_build_dep() {
25672567
"\
25682568
[COMPILING] foo v0.0.1 ([CWD])
25692569
[COMPILING] d1 v0.0.1 ([CWD]/d1)
2570-
[RUNNING] `rustc --crate-name build_script_build [..]--crate-type bin[..]
2571-
[RUNNING] `rustc --crate-name d1 [..]--crate-type bin[..]
2570+
[RUNNING] `rustc --crate-name build_script_build --edition=2021 [..]--crate-type bin[..]
2571+
[RUNNING] `rustc --crate-name d1 --edition=2021 [..]--crate-type bin[..]
25722572
[RUNNING] `[CWD]/target/debug/build/foo-[..]/build-script-build`
2573-
[RUNNING] `rustc --crate-name foo [..]--cfg[..]d1[..]
2573+
[RUNNING] `rustc --crate-name foo --edition=2021 [..]--cfg[..]d1[..]
25742574
[FINISHED] `dev` profile [..]
25752575
",
25762576
)

tests/testsuite/build.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,14 +1426,14 @@ fn cargo_default_env_metadata_env_var() {
14261426
.with_stderr(&format!(
14271427
"\
14281428
[COMPILING] bar v0.0.1 ([CWD]/bar)
1429-
[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--crate-type dylib \
1429+
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]--crate-type dylib \
14301430
--emit=[..]link \
14311431
-C prefer-dynamic[..]-C debuginfo=2 [..]\
14321432
-C metadata=[..] \
14331433
--out-dir [..] \
14341434
-L dependency=[CWD]/target/debug/deps`
14351435
[COMPILING] foo v0.0.1 ([CWD])
1436-
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
1436+
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
14371437
--emit=[..]link[..]-C debuginfo=2 [..]\
14381438
-C metadata=[..] \
14391439
-C extra-filename=[..] \
@@ -1454,14 +1454,14 @@ fn cargo_default_env_metadata_env_var() {
14541454
.with_stderr(&format!(
14551455
"\
14561456
[COMPILING] bar v0.0.1 ([CWD]/bar)
1457-
[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--crate-type dylib \
1457+
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]--crate-type dylib \
14581458
--emit=[..]link \
14591459
-C prefer-dynamic[..]-C debuginfo=2 [..]\
14601460
-C metadata=[..] \
14611461
--out-dir [..] \
14621462
-L dependency=[CWD]/target/debug/deps`
14631463
[COMPILING] foo v0.0.1 ([CWD])
1464-
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
1464+
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
14651465
--emit=[..]link[..]-C debuginfo=2 [..]\
14661466
-C metadata=[..] \
14671467
-C extra-filename=[..] \
@@ -2326,7 +2326,7 @@ fn lto_build() {
23262326
.with_stderr(
23272327
"\
23282328
[COMPILING] test v0.0.0 ([CWD])
2329-
[RUNNING] `rustc --crate-name test src/main.rs [..]--crate-type bin \
2329+
[RUNNING] `rustc --crate-name test --edition=2015 src/main.rs [..]--crate-type bin \
23302330
--emit=[..]link \
23312331
-C opt-level=3 \
23322332
-C lto \
@@ -2344,7 +2344,7 @@ fn verbose_build() {
23442344
.with_stderr(
23452345
"\
23462346
[COMPILING] foo v0.0.1 ([CWD])
2347-
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
2347+
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
23482348
--emit=[..]link[..]-C debuginfo=2 [..]\
23492349
-C metadata=[..] \
23502350
--out-dir [..] \
@@ -2362,7 +2362,7 @@ fn verbose_release_build() {
23622362
.with_stderr(
23632363
"\
23642364
[COMPILING] foo v0.0.1 ([CWD])
2365-
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
2365+
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
23662366
--emit=[..]link[..]\
23672367
-C opt-level=3[..]\
23682368
-C metadata=[..] \
@@ -2381,7 +2381,7 @@ fn verbose_release_build_short() {
23812381
.with_stderr(
23822382
"\
23832383
[COMPILING] foo v0.0.1 ([CWD])
2384-
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
2384+
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
23852385
--emit=[..]link[..]\
23862386
-C opt-level=3[..]\
23872387
-C metadata=[..] \
@@ -2430,7 +2430,7 @@ fn verbose_release_build_deps() {
24302430
.with_stderr(&format!(
24312431
"\
24322432
[COMPILING] foo v0.0.0 ([CWD]/foo)
2433-
[RUNNING] `rustc --crate-name foo foo/src/lib.rs [..]\
2433+
[RUNNING] `rustc --crate-name foo --edition=2015 foo/src/lib.rs [..]\
24342434
--crate-type dylib --crate-type rlib \
24352435
--emit=[..]link \
24362436
-C prefer-dynamic[..]\
@@ -2439,7 +2439,7 @@ fn verbose_release_build_deps() {
24392439
--out-dir [..] \
24402440
-L dependency=[CWD]/target/release/deps`
24412441
[COMPILING] test v0.0.0 ([CWD])
2442-
[RUNNING] `rustc --crate-name test src/lib.rs [..]--crate-type lib \
2442+
[RUNNING] `rustc --crate-name test --edition=2015 src/lib.rs [..]--crate-type lib \
24432443
--emit=[..]link[..]\
24442444
-C opt-level=3[..]\
24452445
-C metadata=[..] \
@@ -5704,27 +5704,27 @@ fn build_filter_infer_profile() {
57045704

57055705
p.cargo("build -v")
57065706
.with_stderr_contains(
5707-
"[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
5707+
"[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
57085708
--emit=[..]link[..]",
57095709
)
57105710
.with_stderr_contains(
5711-
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
5711+
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--crate-type bin \
57125712
--emit=[..]link[..]",
57135713
)
57145714
.run();
57155715

57165716
p.root().join("target").rm_rf();
57175717
p.cargo("build -v --test=t1")
57185718
.with_stderr_contains(
5719-
"[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
5719+
"[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
57205720
--emit=[..]link[..]-C debuginfo=2 [..]",
57215721
)
57225722
.with_stderr_contains(
5723-
"[RUNNING] `rustc --crate-name t1 tests/t1.rs [..]--emit=[..]link[..]\
5723+
"[RUNNING] `rustc --crate-name t1 --edition=2015 tests/t1.rs [..]--emit=[..]link[..]\
57245724
-C debuginfo=2 [..]",
57255725
)
57265726
.with_stderr_contains(
5727-
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
5727+
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--crate-type bin \
57285728
--emit=[..]link[..]-C debuginfo=2 [..]",
57295729
)
57305730
.run();
@@ -5733,16 +5733,16 @@ fn build_filter_infer_profile() {
57335733
// Bench uses test profile without `--release`.
57345734
p.cargo("build -v --bench=b1")
57355735
.with_stderr_contains(
5736-
"[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
5736+
"[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
57375737
--emit=[..]link[..]-C debuginfo=2 [..]",
57385738
)
57395739
.with_stderr_contains(
5740-
"[RUNNING] `rustc --crate-name b1 benches/b1.rs [..]--emit=[..]link[..]\
5740+
"[RUNNING] `rustc --crate-name b1 --edition=2015 benches/b1.rs [..]--emit=[..]link[..]\
57415741
-C debuginfo=2 [..]",
57425742
)
57435743
.with_stderr_does_not_contain("opt-level")
57445744
.with_stderr_contains(
5745-
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
5745+
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--crate-type bin \
57465746
--emit=[..]link[..]-C debuginfo=2 [..]",
57475747
)
57485748
.run();
@@ -5754,17 +5754,17 @@ fn targets_selected_default() {
57545754
p.cargo("build -v")
57555755
// Binaries.
57565756
.with_stderr_contains(
5757-
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
5757+
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--crate-type bin \
57585758
--emit=[..]link[..]",
57595759
)
57605760
// Benchmarks.
57615761
.with_stderr_does_not_contain(
5762-
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link \
5762+
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--emit=[..]link \
57635763
-C opt-level=3 --test [..]",
57645764
)
57655765
// Unit tests.
57665766
.with_stderr_does_not_contain(
5767-
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link[..]\
5767+
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--emit=[..]link[..]\
57685768
-C debuginfo=2 --test [..]",
57695769
)
57705770
.run();
@@ -5776,12 +5776,12 @@ fn targets_selected_all() {
57765776
p.cargo("build -v --all-targets")
57775777
// Binaries.
57785778
.with_stderr_contains(
5779-
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
5779+
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--crate-type bin \
57805780
--emit=[..]link[..]",
57815781
)
57825782
// Unit tests.
57835783
.with_stderr_contains(
5784-
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link[..]\
5784+
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--emit=[..]link[..]\
57855785
-C debuginfo=2 [..]--test [..]",
57865786
)
57875787
.run();
@@ -5793,12 +5793,12 @@ fn all_targets_no_lib() {
57935793
p.cargo("build -v --all-targets")
57945794
// Binaries.
57955795
.with_stderr_contains(
5796-
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
5796+
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--crate-type bin \
57975797
--emit=[..]link[..]",
57985798
)
57995799
// Unit tests.
58005800
.with_stderr_contains(
5801-
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link[..]\
5801+
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--emit=[..]link[..]\
58025802
-C debuginfo=2 [..]--test [..]",
58035803
)
58045804
.run();
@@ -6271,7 +6271,7 @@ fn build_lib_only() {
62716271
.with_stderr(
62726272
"\
62736273
[COMPILING] foo v0.0.1 ([CWD])
6274-
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
6274+
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
62756275
--emit=[..]link[..]-C debuginfo=2 [..]\
62766276
-C metadata=[..] \
62776277
--out-dir [..] \

0 commit comments

Comments
 (0)