Skip to content

Commit 1782d13

Browse files
authored
Rollup merge of rust-lang#90070 - llogiq:compiletest-config-edition, r=Mark-Simulacrum
Add edition configuration to compiletest This allows the compiletest configuration to set a default edition that can still be overridden with header annotations. Doing this will make it far easier for clippy to get our tests to the newest edition. r? ```@Manishearth```
2 parents 8fb194c + 65b3c85 commit 1782d13

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/tools/compiletest/src/common.rs

+3
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ pub struct Config {
349349
/// The current Rust channel
350350
pub channel: String,
351351

352+
/// The default Rust edition
353+
pub edition: Option<String>,
354+
352355
// Configuration for various run-make tests frobbing things like C compilers
353356
// or querying about various LLVM component information.
354357
pub cc: String,

src/tools/compiletest/src/header.rs

+6
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ impl TestProps {
222222
/// `//[foo]`), then the property is ignored unless `cfg` is
223223
/// `Some("foo")`.
224224
fn load_from(&mut self, testfile: &Path, cfg: Option<&str>, config: &Config) {
225+
let mut has_edition = false;
225226
if !testfile.is_dir() {
226227
let file = File::open(testfile).unwrap();
227228

@@ -240,6 +241,7 @@ impl TestProps {
240241

241242
if let Some(edition) = config.parse_edition(ln) {
242243
self.compile_flags.push(format!("--edition={}", edition));
244+
has_edition = true;
243245
if edition == "2021" {
244246
self.compile_flags.push("-Zunstable-options".to_string());
245247
}
@@ -391,6 +393,10 @@ impl TestProps {
391393
}
392394
}
393395
}
396+
397+
if let (Some(edition), false) = (&config.edition, has_edition) {
398+
self.compile_flags.push(format!("--edition={}", edition));
399+
}
394400
}
395401

396402
fn update_fail_mode(&mut self, ln: &str, config: &Config) {

src/tools/compiletest/src/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
147147
)
148148
.optflag("", "force-rerun", "rerun tests even if the inputs are unchanged")
149149
.optflag("h", "help", "show this message")
150-
.reqopt("", "channel", "current Rust channel", "CHANNEL");
150+
.reqopt("", "channel", "current Rust channel", "CHANNEL")
151+
.optopt("", "edition", "default Rust edition", "EDITION");
151152

152153
let (argv0, args_) = args.split_first().unwrap();
153154
if args.len() == 1 || args[1] == "-h" || args[1] == "--help" {
@@ -282,6 +283,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
282283
rustfix_coverage: matches.opt_present("rustfix-coverage"),
283284
has_tidy,
284285
channel: matches.opt_str("channel").unwrap(),
286+
edition: matches.opt_str("edition"),
285287

286288
cc: matches.opt_str("cc").unwrap(),
287289
cxx: matches.opt_str("cxx").unwrap(),

0 commit comments

Comments
 (0)