Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions src/tools/compiletest/src/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ pub(crate) struct TestProps {
// Regexes that should be expected, in order, on standard out
pub(crate) regex_error_patterns: Vec<String>,
/// Edition selected by an `//@ edition` directive, if any.
///
/// Automatically added to `compile_flags` during directive processing.
pub(crate) edition: Option<Edition>,
// Extra flags to pass to the compiler
// Extra flags to pass to the compiler.
pub(crate) compile_flags: Vec<String>,
// Extra flags to pass when the compiled code is run (such as --bench)
pub(crate) run_flags: Vec<String>,
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions src/tools/compiletest/src/edition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ pub(crate) enum Edition {
Future,
}

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 {

@fmease fmease Nov 5, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies in advance for potential abstraction layer violations.

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine, it's a bit of a mess already. I need to clean this up...

format!("--edition={self}")
}
}

impl std::fmt::Display for Edition {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down
22 changes: 22 additions & 0 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -982,6 +993,7 @@ impl<'test> TestCx<'test> {
emit,
allow_unused,
LinkToAux::Yes,
self.edition(),
passes,
);

Expand Down Expand Up @@ -1065,6 +1077,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);

Expand Down Expand Up @@ -1105,6 +1118,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")
Expand Down Expand Up @@ -1383,13 +1397,17 @@ impl<'test> TestCx<'test> {
/// directory.
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,
TargetLocation::ThisFile(output_file_path.clone()),
Emit::None,
AllowUnused::Yes,
LinkToAux::No,
Edition::LATEST_STABLE,
vec![],
);

Expand Down Expand Up @@ -1471,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);
Expand Down Expand Up @@ -1657,6 +1676,7 @@ impl<'test> TestCx<'test> {
emit: Emit,
allow_unused: AllowUnused,
link_to_aux: LinkToAux,
edition: Edition,
passes: Vec<String>, // Vec of passes under mir-opt test to be dumped
) -> Command {
// FIXME(Zalathar): We should have a cleaner distinction between
Expand Down Expand Up @@ -2041,6 +2061,7 @@ impl<'test> TestCx<'test> {
compiler.arg("-Cforce-unwind-tables=yes");
}

compiler.arg(edition.to_flag());
compiler.args(&self.props.compile_flags);

compiler
Expand Down Expand Up @@ -2267,6 +2288,7 @@ impl<'test> TestCx<'test> {
Emit::LlvmIr,
AllowUnused::No,
LinkToAux::Yes,
self.edition(),
Vec::new(),
);

Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/src/runtest/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl TestCx<'_> {
emit,
AllowUnused::No,
LinkToAux::Yes,
self.edition(),
Vec::new(),
);

Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/src/runtest/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ impl TestCx<'_> {
emit_metadata,
AllowUnused::No,
LinkToAux::Yes,
self.edition(),
Vec::new(),
);

Expand Down
6 changes: 2 additions & 4 deletions src/tools/compiletest/src/rustdoc_gui_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment on lines +36 to +37

@jieyouxu jieyouxu Nov 5, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(rustdoc_gui_test is a bit of an hack, and honestly I'm not sure... IIRC rustdoc_gui_test didn't want to mirror/reimpl test directive handling which is why there's a bit of an hack.)

Self { compile_flags, run_flags }
}
}
Expand Down
Loading