Skip to content

Commit

Permalink
Auto merge of #13499 - epage:always-edition, r=weihanglo
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Feb 28, 2024
2 parents a3ba4ee + 831847e commit 2bdaed6
Show file tree
Hide file tree
Showing 22 changed files with 299 additions and 288 deletions.
4 changes: 1 addition & 3 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,7 @@ impl Edition {
/// Updates the given [`ProcessBuilder`] to include the appropriate flags
/// for setting the edition.
pub(crate) fn cmd_edition_arg(&self, cmd: &mut ProcessBuilder) {
if *self != Edition::Edition2015 {
cmd.arg(format!("--edition={}", self));
}
cmd.arg(format!("--edition={}", self));
if !self.is_stable() {
cmd.arg("-Z").arg("unstable-options");
}
Expand Down
38 changes: 19 additions & 19 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,16 +1057,16 @@ fn build_script_deps_adopt_specified_target_unconditionally() {
p.cargo("check -v -Z bindeps")
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr_does_not_contain(format!(
"[RUNNING] `rustc --crate-name build_script_build build.rs [..]--target {} [..]",
"[RUNNING] `rustc --crate-name build_script_build --edition=2015 build.rs [..]--target {} [..]",
target
))
.with_stderr_contains("[RUNNING] `rustc --crate-name build_script_build build.rs [..]")
.with_stderr_contains("[RUNNING] `rustc --crate-name build_script_build --edition=2015 build.rs [..]")
.with_stderr_contains(format!(
"[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--target {} [..]",
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]--target {} [..]",
target
))
.with_stderr_contains(format!(
"[RUNNING] `rustc --crate-name bar bar/src/main.rs [..]--target {} [..]",
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..]--target {} [..]",
target
))
.with_stderr_does_not_contain(format!(
Expand Down Expand Up @@ -1172,11 +1172,11 @@ fn non_build_script_deps_adopt_specified_target_unconditionally() {
p.cargo("check -v -Z bindeps")
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr_contains(format!(
"[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--target {} [..]",
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]--target {} [..]",
target
))
.with_stderr_contains(format!(
"[RUNNING] `rustc --crate-name bar bar/src/main.rs [..]--target {} [..]",
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..]--target {} [..]",
target
))
.with_stderr_does_not_contain(format!(
Expand Down Expand Up @@ -1251,8 +1251,8 @@ fn no_cross_doctests_works_with_artifacts() {
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr_contains(format!(
"[COMPILING] bar v0.5.0 ([CWD]/bar)
[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--target {triple} [..]
[RUNNING] `rustc --crate-name bar bar/src/main.rs [..]--target {triple} [..]
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]--target {triple} [..]
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..]--target {triple} [..]
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo [..]
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..]",
Expand Down Expand Up @@ -1315,16 +1315,16 @@ fn build_script_deps_adopts_target_platform_if_target_equals_target() {
.arg(alternate_target)
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr_does_not_contain(format!(
"[RUNNING] `rustc --crate-name build_script_build build.rs [..]--target {} [..]",
"[RUNNING] `rustc --crate-name build_script_build --edition=2015 build.rs [..]--target {} [..]",
alternate_target
))
.with_stderr_contains("[RUNNING] `rustc --crate-name build_script_build build.rs [..]")
.with_stderr_contains("[RUNNING] `rustc --crate-name build_script_build --edition=2015 build.rs [..]")
.with_stderr_contains(format!(
"[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--target {} [..]",
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]--target {} [..]",
alternate_target
))
.with_stderr_contains(format!(
"[RUNNING] `rustc --crate-name bar bar/src/main.rs [..]--target {} [..]",
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..]--target {} [..]",
alternate_target
))
.with_stderr_contains(format!(
Expand Down Expand Up @@ -1373,16 +1373,16 @@ fn profile_override_basic() {
"[RUNNING] `rustc --crate-name build_script_build [..] -C opt-level=1 [..]`",
)
.with_stderr_contains(
"[RUNNING] `rustc --crate-name bar bar/src/main.rs [..] -C opt-level=3 [..]`",
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..] -C opt-level=3 [..]`",
)
.with_stderr_contains(
"[RUNNING] `rustc --crate-name bar bar/src/main.rs [..] -C opt-level=1 [..]`",
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..] -C opt-level=1 [..]`",
)
.with_stderr_contains(
"[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..] -C opt-level=1 [..]`",
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..] -C opt-level=1 [..]`",
)
.with_stderr_contains(
"[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..] -C opt-level=3 [..]`",
"[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..] -C opt-level=3 [..]`",
)
.with_stderr_contains("[RUNNING] `rustc --crate-name foo [..] -C opt-level=3 [..]`")
.run();
Expand Down Expand Up @@ -2567,10 +2567,10 @@ fn with_assumed_host_target_and_optional_build_dep() {
"\
[COMPILING] foo v0.0.1 ([CWD])
[COMPILING] d1 v0.0.1 ([CWD]/d1)
[RUNNING] `rustc --crate-name build_script_build [..]--crate-type bin[..]
[RUNNING] `rustc --crate-name d1 [..]--crate-type bin[..]
[RUNNING] `rustc --crate-name build_script_build --edition=2021 [..]--crate-type bin[..]
[RUNNING] `rustc --crate-name d1 --edition=2021 [..]--crate-type bin[..]
[RUNNING] `[CWD]/target/debug/build/foo-[..]/build-script-build`
[RUNNING] `rustc --crate-name foo [..]--cfg[..]d1[..]
[RUNNING] `rustc --crate-name foo --edition=2021 [..]--cfg[..]d1[..]
[FINISHED] `dev` profile [..]
",
)
Expand Down
52 changes: 26 additions & 26 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1426,14 +1426,14 @@ fn cargo_default_env_metadata_env_var() {
.with_stderr(&format!(
"\
[COMPILING] bar v0.0.1 ([CWD]/bar)
[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--crate-type dylib \
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]--crate-type dylib \
--emit=[..]link \
-C prefer-dynamic[..]-C debuginfo=2 [..]\
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps`
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
--emit=[..]link[..]-C debuginfo=2 [..]\
-C metadata=[..] \
-C extra-filename=[..] \
Expand All @@ -1454,14 +1454,14 @@ fn cargo_default_env_metadata_env_var() {
.with_stderr(&format!(
"\
[COMPILING] bar v0.0.1 ([CWD]/bar)
[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--crate-type dylib \
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]--crate-type dylib \
--emit=[..]link \
-C prefer-dynamic[..]-C debuginfo=2 [..]\
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps`
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
--emit=[..]link[..]-C debuginfo=2 [..]\
-C metadata=[..] \
-C extra-filename=[..] \
Expand Down Expand Up @@ -2326,7 +2326,7 @@ fn lto_build() {
.with_stderr(
"\
[COMPILING] test v0.0.0 ([CWD])
[RUNNING] `rustc --crate-name test src/main.rs [..]--crate-type bin \
[RUNNING] `rustc --crate-name test --edition=2015 src/main.rs [..]--crate-type bin \
--emit=[..]link \
-C opt-level=3 \
-C lto \
Expand All @@ -2344,7 +2344,7 @@ fn verbose_build() {
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
--emit=[..]link[..]-C debuginfo=2 [..]\
-C metadata=[..] \
--out-dir [..] \
Expand All @@ -2362,7 +2362,7 @@ fn verbose_release_build() {
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
--emit=[..]link[..]\
-C opt-level=3[..]\
-C metadata=[..] \
Expand All @@ -2381,7 +2381,7 @@ fn verbose_release_build_short() {
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
--emit=[..]link[..]\
-C opt-level=3[..]\
-C metadata=[..] \
Expand Down Expand Up @@ -2430,7 +2430,7 @@ fn verbose_release_build_deps() {
.with_stderr(&format!(
"\
[COMPILING] foo v0.0.0 ([CWD]/foo)
[RUNNING] `rustc --crate-name foo foo/src/lib.rs [..]\
[RUNNING] `rustc --crate-name foo --edition=2015 foo/src/lib.rs [..]\
--crate-type dylib --crate-type rlib \
--emit=[..]link \
-C prefer-dynamic[..]\
Expand All @@ -2439,7 +2439,7 @@ fn verbose_release_build_deps() {
--out-dir [..] \
-L dependency=[CWD]/target/release/deps`
[COMPILING] test v0.0.0 ([CWD])
[RUNNING] `rustc --crate-name test src/lib.rs [..]--crate-type lib \
[RUNNING] `rustc --crate-name test --edition=2015 src/lib.rs [..]--crate-type lib \
--emit=[..]link[..]\
-C opt-level=3[..]\
-C metadata=[..] \
Expand Down Expand Up @@ -5704,27 +5704,27 @@ fn build_filter_infer_profile() {

p.cargo("build -v")
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
"[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
--emit=[..]link[..]",
)
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--crate-type bin \
--emit=[..]link[..]",
)
.run();

p.root().join("target").rm_rf();
p.cargo("build -v --test=t1")
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
"[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
--emit=[..]link[..]-C debuginfo=2 [..]",
)
.with_stderr_contains(
"[RUNNING] `rustc --crate-name t1 tests/t1.rs [..]--emit=[..]link[..]\
"[RUNNING] `rustc --crate-name t1 --edition=2015 tests/t1.rs [..]--emit=[..]link[..]\
-C debuginfo=2 [..]",
)
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--crate-type bin \
--emit=[..]link[..]-C debuginfo=2 [..]",
)
.run();
Expand All @@ -5733,16 +5733,16 @@ fn build_filter_infer_profile() {
// Bench uses test profile without `--release`.
p.cargo("build -v --bench=b1")
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
"[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
--emit=[..]link[..]-C debuginfo=2 [..]",
)
.with_stderr_contains(
"[RUNNING] `rustc --crate-name b1 benches/b1.rs [..]--emit=[..]link[..]\
"[RUNNING] `rustc --crate-name b1 --edition=2015 benches/b1.rs [..]--emit=[..]link[..]\
-C debuginfo=2 [..]",
)
.with_stderr_does_not_contain("opt-level")
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--crate-type bin \
--emit=[..]link[..]-C debuginfo=2 [..]",
)
.run();
Expand All @@ -5754,17 +5754,17 @@ fn targets_selected_default() {
p.cargo("build -v")
// Binaries.
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--crate-type bin \
--emit=[..]link[..]",
)
// Benchmarks.
.with_stderr_does_not_contain(
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link \
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--emit=[..]link \
-C opt-level=3 --test [..]",
)
// Unit tests.
.with_stderr_does_not_contain(
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link[..]\
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--emit=[..]link[..]\
-C debuginfo=2 --test [..]",
)
.run();
Expand All @@ -5776,12 +5776,12 @@ fn targets_selected_all() {
p.cargo("build -v --all-targets")
// Binaries.
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--crate-type bin \
--emit=[..]link[..]",
)
// Unit tests.
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link[..]\
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--emit=[..]link[..]\
-C debuginfo=2 [..]--test [..]",
)
.run();
Expand All @@ -5793,12 +5793,12 @@ fn all_targets_no_lib() {
p.cargo("build -v --all-targets")
// Binaries.
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--crate-type bin \
--emit=[..]link[..]",
)
// Unit tests.
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link[..]\
"[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--emit=[..]link[..]\
-C debuginfo=2 [..]--test [..]",
)
.run();
Expand Down Expand Up @@ -6271,7 +6271,7 @@ fn build_lib_only() {
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
--emit=[..]link[..]-C debuginfo=2 [..]\
-C metadata=[..] \
--out-dir [..] \
Expand Down
Loading

0 comments on commit 2bdaed6

Please sign in to comment.