about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEric Huss <eric@huss.org>2025-04-26 14:08:36 -0700
committerEric Huss <eric@huss.org>2025-04-26 14:08:36 -0700
commit8608a3f637871c157b030f5661231f8261ca9797 (patch)
tree6811d338bf5f1eaa4a53037ce7b156661a6afa92
parent5ae50d3b2182f81eea4e4d90e8da3653547215b5 (diff)
downloadrust-8608a3f637871c157b030f5661231f8261ca9797.tar.gz
rust-8608a3f637871c157b030f5661231f8261ca9797.zip
lint-docs: Don't hard-code the valid editions
This removes the hard-coded list of edition support in the lint-docs
tool, and instead just assumes the edition attribute is something valid.
There isn't a real reason to have this, as rustc will error if given a
wrong number. This should be easier to maintain going forward.
-rw-r--r--src/tools/lint-docs/src/lib.rs22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/tools/lint-docs/src/lib.rs b/src/tools/lint-docs/src/lib.rs
index 9fd33e23204..7e00697a0bd 100644
--- a/src/tools/lint-docs/src/lib.rs
+++ b/src/tools/lint-docs/src/lib.rs
@@ -444,21 +444,15 @@ impl<'a> LintExtractor<'a> {
         fs::write(&tempfile, source)
             .map_err(|e| format!("failed to write {}: {}", tempfile.display(), e))?;
         let mut cmd = Command::new(self.rustc_path);
-        if options.contains(&"edition2024") {
-            cmd.arg("--edition=2024");
-            cmd.arg("-Zunstable-options");
-        } else if options.contains(&"edition2021") {
-            cmd.arg("--edition=2021");
-        } else if options.contains(&"edition2018") {
-            cmd.arg("--edition=2018");
-        } else if options.contains(&"edition2015") {
-            cmd.arg("--edition=2015");
-        } else if options.contains(&"edition") {
-            panic!("lint-docs: unknown edition");
-        } else {
+        let edition = options
+            .iter()
+            .filter_map(|opt| opt.strip_prefix("edition"))
+            .next()
             // defaults to latest edition
-            cmd.arg("--edition=2021");
-        }
+            .unwrap_or("2021");
+        cmd.arg(format!("--edition={edition}"));
+        // Just in case this is an unstable edition.
+        cmd.arg("-Zunstable-options");
         cmd.arg("--error-format=json");
         cmd.arg("--target").arg(self.rustc_target);
         if let Some(target_linker) = self.rustc_linker {