From 9164cd164cd8e9033f912bc3a858da9106ed0737 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 10 Dec 2023 22:54:06 +0100 Subject: [PATCH] ./miri run: default to edition 2021 --- src/tools/miri/miri-script/src/commands.rs | 15 ++++++++++++--- src/tools/miri/tests/compiletest.rs | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/tools/miri/miri-script/src/commands.rs b/src/tools/miri/miri-script/src/commands.rs index e4789c696b390..0b3c4fb985bed 100644 --- a/src/tools/miri/miri-script/src/commands.rs +++ b/src/tools/miri/miri-script/src/commands.rs @@ -478,7 +478,11 @@ impl Command { // Scan for "--target" to overwrite the "MIRI_TEST_TARGET" env var so // that we set the MIRI_SYSROOT up the right way. use itertools::Itertools; - let target = flags.iter().tuple_windows().find(|(first, _)| first == &"--target"); + let target = flags + .iter() + .take_while(|arg| *arg != "--") + .tuple_windows() + .find(|(first, _)| *first == "--target"); if let Some((_, target)) = target { // Found it! e.sh.set_var("MIRI_TEST_TARGET", target); @@ -487,6 +491,10 @@ impl Command { let miriflags = e.sh.var("MIRIFLAGS").unwrap_or_default(); e.sh.set_var("MIRIFLAGS", format!("{miriflags} --target {target}")); } + // Scan for "--edition" (we'll set one ourselves if that flag is not present). + let have_edition = + flags.iter().take_while(|arg| *arg != "--").any(|arg| *arg == "--edition"); + // Prepare a sysroot. e.build_miri_sysroot(/* quiet */ true)?; @@ -496,15 +504,16 @@ impl Command { let miri_flags = flagsplit(&miri_flags); let toolchain = &e.toolchain; let extra_flags = &e.cargo_extra_flags; + let edition_flags = (!have_edition).then_some("--edition=2021"); // keep in sync with `compiletest.rs`.` if dep { cmd!( e.sh, - "cargo +{toolchain} --quiet test --test compiletest {extra_flags...} --manifest-path {miri_manifest} -- --miri-run-dep-mode {miri_flags...} {flags...}" + "cargo +{toolchain} --quiet test --test compiletest {extra_flags...} --manifest-path {miri_manifest} -- --miri-run-dep-mode {miri_flags...} {edition_flags...} {flags...}" ).quiet().run()?; } else { cmd!( e.sh, - "cargo +{toolchain} --quiet run {extra_flags...} --manifest-path {miri_manifest} -- {miri_flags...} {flags...}" + "cargo +{toolchain} --quiet run {extra_flags...} --manifest-path {miri_manifest} -- {miri_flags...} {edition_flags...} {flags...}" ).quiet().run()?; } Ok(()) diff --git a/src/tools/miri/tests/compiletest.rs b/src/tools/miri/tests/compiletest.rs index 91df4985c0f0c..3394c4a49f836 100644 --- a/src/tools/miri/tests/compiletest.rs +++ b/src/tools/miri/tests/compiletest.rs @@ -91,7 +91,7 @@ fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) -> mode, program, out_dir: PathBuf::from(std::env::var_os("CARGO_TARGET_DIR").unwrap()).join("ui"), - edition: Some("2021".into()), + edition: Some("2021".into()), // keep in sync with `./miri run` threads: std::env::var("MIRI_TEST_THREADS") .ok() .map(|threads| NonZeroUsize::new(threads.parse().unwrap()).unwrap()),