From 7c647296d9459a8c97df59acafba02f6f9bbf507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Thu, 5 Nov 2026 03:32:15 +0100 Subject: [PATCH 1/2] Don't eagerly lower `TestProps.edition` to `TestProps.compile_flags` --- src/tools/compiletest/src/directives.rs | 9 +-------- src/tools/compiletest/src/edition.rs | 8 ++++++++ src/tools/compiletest/src/runtest.rs | 15 +++++++++++++++ src/tools/compiletest/src/rustdoc_gui_test.rs | 6 ++---- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/tools/compiletest/src/directives.rs b/src/tools/compiletest/src/directives.rs index 4ef2b5fd46d65..33b75f6ab860b 100644 --- a/src/tools/compiletest/src/directives.rs +++ b/src/tools/compiletest/src/directives.rs @@ -87,10 +87,8 @@ pub(crate) struct TestProps { // Regexes that should be expected, in order, on standard out pub(crate) regex_error_patterns: Vec, /// Edition selected by an `//@ edition` directive, if any. - /// - /// Automatically added to `compile_flags` during directive processing. pub(crate) edition: Option, - // Extra flags to pass to the compiler + // Extra flags to pass to the compiler. pub(crate) compile_flags: Vec, // Extra flags to pass when the compiled code is run (such as --bench) pub(crate) run_flags: Vec, @@ -405,11 +403,6 @@ impl TestProps { } } } - - let edition = self.edition.or(config.edition).unwrap_or(Edition::Year(2015)); - // The edition is added at the start, since flags from //@compile-flags must be passed - // to rustc last. - self.compile_flags.insert(0, format!("--edition={edition}")); } fn update_pass_fail_mode(&mut self, ln: &DirectiveLine<'_>, config: &Config) { diff --git a/src/tools/compiletest/src/edition.rs b/src/tools/compiletest/src/edition.rs index 95999420daa0b..2ca52fb4638ce 100644 --- a/src/tools/compiletest/src/edition.rs +++ b/src/tools/compiletest/src/edition.rs @@ -10,6 +10,14 @@ pub(crate) enum Edition { Future, } +impl Edition { + pub(crate) const RUSTC_DEFAULT: Self = Self::Year(2015); + + pub(crate) fn to_flag(self) -> String { + format!("--edition={self}") + } +} + impl std::fmt::Display for Edition { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index ddea906f500a2..59fd03d19193b 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -19,6 +19,7 @@ use crate::common::{ UI_WINDOWS_SVG, expected_output_path, incremental_dir, output_base_dir, output_base_name, }; use crate::directives::{AuxCrate, TestProps}; +use crate::edition::Edition; use crate::errors::{Error, ErrorKind, load_errors}; use crate::executor::TestVariant; use crate::output_capture::ConsoleOut; @@ -224,6 +225,14 @@ struct TestCx<'test> { variant: &'test TestVariant, } +impl TestCx<'_> { + fn edition(self) -> Edition { + // We're always explicitly defaulting to rustc's default to suppress the + // warning that rustc emits when no edition gets specified. + self.props.edition.or(self.config.edition).unwrap_or(Edition::RUSTC_DEFAULT) + } +} + enum ReadFrom { Path, Stdin(String), @@ -456,6 +465,7 @@ impl<'test> TestCx<'test> { .arg(&aux_dir) .arg("-A") .arg("internal_features") + .arg(self.edition().to_flag()) .args(&self.props.compile_flags) .envs(self.props.rustc_env.clone()); self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags); @@ -570,6 +580,7 @@ impl<'test> TestCx<'test> { .arg("internal_features"); self.set_revision_flags(&mut rustc); self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags); + rustc.arg(self.edition().to_flag()); rustc.args(&self.props.compile_flags); self.compose_and_run_compiler(rustc, Some(src)) @@ -1065,6 +1076,7 @@ impl<'test> TestCx<'test> { // FIXME(#160895): While the new solver is enabled by default on nightly, // we don't want to use it in our tests for now. .arg("-Znext-solver=coherence") + .arg(self.edition().to_flag()) .args(&self.props.compile_flags) .args(&self.props.doc_flags); @@ -1105,6 +1117,7 @@ impl<'test> TestCx<'test> { rustdoc_merge .arg("-o") .arg(out_dir.as_ref()) + .arg(self.edition().to_flag()) .args(&self.props.compile_flags) .args(&self.props.doc_flags) .arg("--read-doc-meta-dir") @@ -1383,6 +1396,7 @@ impl<'test> TestCx<'test> { /// directory. fn build_minicore(&self) -> Utf8PathBuf { let output_file_path = self.output_base_dir().join("libminicore.rlib"); + let mut rustc = self.make_compile_args( CompilerKind::Rustc, &self.config.minicore_path, @@ -2041,6 +2055,7 @@ impl<'test> TestCx<'test> { compiler.arg("-Cforce-unwind-tables=yes"); } + compiler.arg(self.edition().to_flag()); compiler.args(&self.props.compile_flags); compiler diff --git a/src/tools/compiletest/src/rustdoc_gui_test.rs b/src/tools/compiletest/src/rustdoc_gui_test.rs index 4e1d1138b3168..c0f31984834e1 100644 --- a/src/tools/compiletest/src/rustdoc_gui_test.rs +++ b/src/tools/compiletest/src/rustdoc_gui_test.rs @@ -33,10 +33,8 @@ impl RustdocGuiTestProps { let props = TestProps::from_file(test_file_path, None, &config); - let TestProps { mut compile_flags, run_flags, .. } = props; - // We don't want to pass `--edition=2015` in, which is being set by default by - // `TestProps::from_file`. - compile_flags.remove(0); + // FIXME: Why do we need to ignore the edition? + let TestProps { edition: _, compile_flags, run_flags, .. } = props; Self { compile_flags, run_flags } } } From 3a5b17c34e89745dc9c31061dcd6ec41eea9e060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Thu, 5 Nov 2026 03:42:40 +0100 Subject: [PATCH 2/2] Fix the edition of `minicore` to the latest stable one --- src/tools/compiletest/src/edition.rs | 1 + src/tools/compiletest/src/runtest.rs | 9 ++++++++- src/tools/compiletest/src/runtest/assembly.rs | 1 + src/tools/compiletest/src/runtest/ui.rs | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/edition.rs b/src/tools/compiletest/src/edition.rs index 2ca52fb4638ce..ba401c49c3317 100644 --- a/src/tools/compiletest/src/edition.rs +++ b/src/tools/compiletest/src/edition.rs @@ -12,6 +12,7 @@ pub(crate) enum Edition { impl Edition { pub(crate) const RUSTC_DEFAULT: Self = Self::Year(2015); + pub(crate) const LATEST_STABLE: Self = Self::Year(2024); pub(crate) fn to_flag(self) -> String { format!("--edition={self}") diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 59fd03d19193b..6c6efa10142b4 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -993,6 +993,7 @@ impl<'test> TestCx<'test> { emit, allow_unused, LinkToAux::Yes, + self.edition(), passes, ); @@ -1397,6 +1398,8 @@ impl<'test> TestCx<'test> { fn build_minicore(&self) -> Utf8PathBuf { let output_file_path = self.output_base_dir().join("libminicore.rlib"); + // We want to inherit *all* `TestProps` from the test that added minicore *except* + // for the edition which we want to keep fixed to the latest stable one. let mut rustc = self.make_compile_args( CompilerKind::Rustc, &self.config.minicore_path, @@ -1404,6 +1407,7 @@ impl<'test> TestCx<'test> { Emit::None, AllowUnused::Yes, LinkToAux::No, + Edition::LATEST_STABLE, vec![], ); @@ -1485,6 +1489,7 @@ impl<'test> TestCx<'test> { Emit::None, AllowUnused::No, LinkToAux::No, + aux_cx.edition(), Vec::new(), ); aux_cx.build_all_auxiliary(&aux_dir, &mut aux_rustc); @@ -1671,6 +1676,7 @@ impl<'test> TestCx<'test> { emit: Emit, allow_unused: AllowUnused, link_to_aux: LinkToAux, + edition: Edition, passes: Vec, // Vec of passes under mir-opt test to be dumped ) -> Command { // FIXME(Zalathar): We should have a cleaner distinction between @@ -2055,7 +2061,7 @@ impl<'test> TestCx<'test> { compiler.arg("-Cforce-unwind-tables=yes"); } - compiler.arg(self.edition().to_flag()); + compiler.arg(edition.to_flag()); compiler.args(&self.props.compile_flags); compiler @@ -2282,6 +2288,7 @@ impl<'test> TestCx<'test> { Emit::LlvmIr, AllowUnused::No, LinkToAux::Yes, + self.edition(), Vec::new(), ); diff --git a/src/tools/compiletest/src/runtest/assembly.rs b/src/tools/compiletest/src/runtest/assembly.rs index be2430f006a54..78f713c9ad0f6 100644 --- a/src/tools/compiletest/src/runtest/assembly.rs +++ b/src/tools/compiletest/src/runtest/assembly.rs @@ -42,6 +42,7 @@ impl TestCx<'_> { emit, AllowUnused::No, LinkToAux::Yes, + self.edition(), Vec::new(), ); diff --git a/src/tools/compiletest/src/runtest/ui.rs b/src/tools/compiletest/src/runtest/ui.rs index 4af14e6002c03..da8c2d9c601d4 100644 --- a/src/tools/compiletest/src/runtest/ui.rs +++ b/src/tools/compiletest/src/runtest/ui.rs @@ -260,6 +260,7 @@ impl TestCx<'_> { emit_metadata, AllowUnused::No, LinkToAux::Yes, + self.edition(), Vec::new(), );