Skip to content

Commit e9bcded

Browse files
committed
Store the selected edition in TestProps
1 parent c0c37ca commit e9bcded

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/tools/compiletest/src/directives.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,15 @@ impl EarlyProps {
8181
}
8282

8383
#[derive(Clone, Debug)]
84-
pub struct TestProps {
84+
pub(crate) struct TestProps {
8585
// Lines that should be expected, in order, on standard out
8686
pub error_patterns: Vec<String>,
8787
// Regexes that should be expected, in order, on standard out
8888
pub regex_error_patterns: Vec<String>,
89+
/// Edition selected by an `//@ edition` directive, if any.
90+
///
91+
/// Automatically added to `compile_flags` during directive processing.
92+
pub edition: Option<Edition>,
8993
// Extra flags to pass to the compiler
9094
pub compile_flags: Vec<String>,
9195
// Extra flags to pass when the compiled code is run (such as --bench)
@@ -267,6 +271,7 @@ impl TestProps {
267271
TestProps {
268272
error_patterns: vec![],
269273
regex_error_patterns: vec![],
274+
edition: None,
270275
compile_flags: vec![],
271276
run_flags: vec![],
272277
doc_flags: vec![],
@@ -355,7 +360,6 @@ impl TestProps {
355360
/// `//@[foo]`), then the property is ignored unless `test_revision` is
356361
/// `Some("foo")`.
357362
fn load_from(&mut self, testfile: &Utf8Path, test_revision: Option<&str>, config: &Config) {
358-
let mut has_edition = false;
359363
if !testfile.is_dir() {
360364
let file_contents = fs::read_to_string(testfile).unwrap();
361365
let file_directives = FileDirectives::from_file_contents(testfile, &file_contents);
@@ -423,13 +427,7 @@ impl TestProps {
423427
}
424428

425429
if let Some(range) = parse_edition_range(config, ln) {
426-
// The edition is added at the start, since flags from //@compile-flags must
427-
// be passed to rustc last.
428-
self.compile_flags.insert(
429-
0,
430-
format!("--edition={}", range.edition_to_test(config.edition)),
431-
);
432-
has_edition = true;
430+
self.edition = Some(range.edition_to_test(config.edition));
433431
}
434432

435433
config.parse_and_update_revisions(ln, &mut self.revisions);
@@ -678,10 +676,10 @@ impl TestProps {
678676
}
679677
}
680678

681-
if let (Some(edition), false) = (&config.edition, has_edition) {
679+
if let Some(edition) = self.edition.or(config.edition) {
682680
// The edition is added at the start, since flags from //@compile-flags must be passed
683681
// to rustc last.
684-
self.compile_flags.insert(0, format!("--edition={}", edition));
682+
self.compile_flags.insert(0, format!("--edition={edition}"));
685683
}
686684
}
687685

src/tools/compiletest/src/directives/tests.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,18 @@ fn parse_edition_range(line: &str) -> Option<EditionRange> {
961961
super::parse_edition_range(&config, &line)
962962
}
963963

964+
#[test]
965+
fn edition_order() {
966+
let editions = &[
967+
Edition::Year(2015),
968+
Edition::Year(2018),
969+
Edition::Year(2021),
970+
Edition::Year(2024),
971+
Edition::Future,
972+
];
973+
assert!(editions.is_sorted(), "{editions:#?}");
974+
}
975+
964976
#[test]
965977
fn test_parse_edition_range() {
966978
assert_eq!(None, parse_edition_range("hello-world"));

0 commit comments

Comments
 (0)