about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-08-01 20:10:19 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-08-02 10:02:02 +0000
commit7742be0095391591c7063465d82f836bdd4787b7 (patch)
treed454e63341439611b4b62a9fd1fdec75bf88fe9e
parenta886938671e1fde9d7271dce8ca3d6938bae9d2e (diff)
downloadrust-7742be0095391591c7063465d82f836bdd4787b7.tar.gz
rust-7742be0095391591c7063465d82f836bdd4787b7.zip
Handle virtual workspaces in the tidy edition check
-rw-r--r--src/tools/tidy/src/edition.rs16
1 files changed, 9 insertions, 7 deletions
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 std::path::Path;
 
 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",