diff --git a/src/tools/tidy/src/edition.rs b/src/tools/tidy/src/edition.rs index d658fe13d36..6a58d58dbde 100644 --- a/src/tools/tidy/src/edition.rs +++ b/src/tools/tidy/src/edition.rs @@ -4,11 +4,6 @@ use crate::walk::{filter_dirs, walk}; -fn is_edition_2021(mut line: &str) -> bool { - line = line.trim(); - line == "edition = \"2021\"" -} - pub fn check(path: &Path, bad: &mut bool) { walk(path, |path, _is_dir| filter_dirs(path), &mut |entry, contents| { let file = entry.path(); @@ -17,8 +12,15 @@ pub fn check(path: &Path, bad: &mut bool) { return; } - let is_2021 = contents.lines().any(is_edition_2021); - if !is_2021 { + let is_2021 = contents.lines().any(|line| line.trim() == "edition = \"2021\""); + + let is_workspace = contents.lines().any(|line| line.trim() == "[workspace]"); + let is_package = contents.lines().any(|line| line.trim() == "[package]"); + assert!(is_workspace || is_package); + + // Check that all packages use the 2021 edition. Virtual workspaces don't allow setting an + // edition, so these shouldn't be checked. + if is_package && !is_2021 { tidy_error!( bad, "{} doesn't have `edition = \"2021\"` on a separate line",