Skip to content

Commit 8608a3f

Browse files
committed
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.
1 parent 5ae50d3 commit 8608a3f

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/tools/lint-docs/src/lib.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -444,21 +444,15 @@ impl<'a> LintExtractor<'a> {
444444
fs::write(&tempfile, source)
445445
.map_err(|e| format!("failed to write {}: {}", tempfile.display(), e))?;
446446
let mut cmd = Command::new(self.rustc_path);
447-
if options.contains(&"edition2024") {
448-
cmd.arg("--edition=2024");
449-
cmd.arg("-Zunstable-options");
450-
} else if options.contains(&"edition2021") {
451-
cmd.arg("--edition=2021");
452-
} else if options.contains(&"edition2018") {
453-
cmd.arg("--edition=2018");
454-
} else if options.contains(&"edition2015") {
455-
cmd.arg("--edition=2015");
456-
} else if options.contains(&"edition") {
457-
panic!("lint-docs: unknown edition");
458-
} else {
447+
let edition = options
448+
.iter()
449+
.filter_map(|opt| opt.strip_prefix("edition"))
450+
.next()
459451
// defaults to latest edition
460-
cmd.arg("--edition=2021");
461-
}
452+
.unwrap_or("2021");
453+
cmd.arg(format!("--edition={edition}"));
454+
// Just in case this is an unstable edition.
455+
cmd.arg("-Zunstable-options");
462456
cmd.arg("--error-format=json");
463457
cmd.arg("--target").arg(self.rustc_target);
464458
if let Some(target_linker) = self.rustc_linker {

0 commit comments

Comments
 (0)