]> git.lizzy.rs Git - rust.git/commitdiff
Add edition configuration to compiletest
authorAndre Bogus <bogusandre@gmail.com>
Tue, 19 Oct 2021 21:06:19 +0000 (23:06 +0200)
committerAndre Bogus <bogusandre@gmail.com>
Wed, 20 Oct 2021 19:55:34 +0000 (21:55 +0200)
src/tools/compiletest/src/common.rs
src/tools/compiletest/src/header.rs
src/tools/compiletest/src/main.rs

index cd0a56d08d8bc6c72d7d5b38db0093f672047652..82fe790a576ab04c8fccc84af8bb1ebc1c1fcdb1 100644 (file)
@@ -349,6 +349,9 @@ pub struct Config {
     /// The current Rust channel
     pub channel: String,
 
+    /// The default Rust edition
+    pub edition: Option<String>,
+
     // Configuration for various run-make tests frobbing things like C compilers
     // or querying about various LLVM component information.
     pub cc: String,
index efd85502799595ab12fc6e31528a3a5510996b88..98d1ee19f69a1ca8bdfb88a533d2d6c41eb5a34b 100644 (file)
@@ -222,6 +222,7 @@ pub fn from_file(testfile: &Path, cfg: Option<&str>, config: &Config) -> Self {
     /// `//[foo]`), then the property is ignored unless `cfg` is
     /// `Some("foo")`.
     fn load_from(&mut self, testfile: &Path, cfg: Option<&str>, config: &Config) {
+        let mut has_edition = false;
         if !testfile.is_dir() {
             let file = File::open(testfile).unwrap();
 
@@ -240,6 +241,7 @@ fn load_from(&mut self, testfile: &Path, cfg: Option<&str>, config: &Config) {
 
                 if let Some(edition) = config.parse_edition(ln) {
                     self.compile_flags.push(format!("--edition={}", edition));
+                    has_edition = true;
                     if edition == "2021" {
                         self.compile_flags.push("-Zunstable-options".to_string());
                     }
@@ -391,6 +393,10 @@ fn load_from(&mut self, testfile: &Path, cfg: Option<&str>, config: &Config) {
                 }
             }
         }
+
+        if let (Some(edition), false) = (&config.edition, has_edition) {
+            self.compile_flags.push(format!("--edition={}", edition));
+        }
     }
 
     fn update_fail_mode(&mut self, ln: &str, config: &Config) {
index 87aba8c5d32bfcae9296c87804bc9853379094fc..58cde108b33221987b025fd0e5dcae64f8c5e8ff 100644 (file)
@@ -147,7 +147,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
         )
         .optflag("", "force-rerun", "rerun tests even if the inputs are unchanged")
         .optflag("h", "help", "show this message")
-        .reqopt("", "channel", "current Rust channel", "CHANNEL");
+        .reqopt("", "channel", "current Rust channel", "CHANNEL")
+        .optopt("", "edition", "default Rust edition", "EDITION");
 
     let (argv0, args_) = args.split_first().unwrap();
     if args.len() == 1 || args[1] == "-h" || args[1] == "--help" {
@@ -282,6 +283,7 @@ fn make_absolute(path: PathBuf) -> PathBuf {
         rustfix_coverage: matches.opt_present("rustfix-coverage"),
         has_tidy,
         channel: matches.opt_str("channel").unwrap(),
+        edition: matches.opt_str("edition"),
 
         cc: matches.opt_str("cc").unwrap(),
         cxx: matches.opt_str("cxx").unwrap(),