diff --git a/miri-script/src/commands.rs b/miri-script/src/commands.rs index e4789c696b..0b3c4fb985 100644 --- a/miri-script/src/commands.rs +++ b/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/tests/compiletest.rs b/tests/compiletest.rs index 91df4985c0..3394c4a49f 100644 --- a/tests/compiletest.rs +++ b/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()),