Skip to content

Commit 7742be0

Browse files
committed
Handle virtual workspaces in the tidy edition check
1 parent a886938 commit 7742be0

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/tools/tidy/src/edition.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ use std::path::Path;
44

55
use crate::walk::{filter_dirs, walk};
66

7-
fn is_edition_2021(mut line: &str) -> bool {
8-
line = line.trim();
9-
line == "edition = \"2021\""
10-
}
11-
127
pub fn check(path: &Path, bad: &mut bool) {
138
walk(path, |path, _is_dir| filter_dirs(path), &mut |entry, contents| {
149
let file = entry.path();
@@ -17,8 +12,15 @@ pub fn check(path: &Path, bad: &mut bool) {
1712
return;
1813
}
1914

20-
let is_2021 = contents.lines().any(is_edition_2021);
21-
if !is_2021 {
15+
let is_2021 = contents.lines().any(|line| line.trim() == "edition = \"2021\"");
16+
17+
let is_workspace = contents.lines().any(|line| line.trim() == "[workspace]");
18+
let is_package = contents.lines().any(|line| line.trim() == "[package]");
19+
assert!(is_workspace || is_package);
20+
21+
// Check that all packages use the 2021 edition. Virtual workspaces don't allow setting an
22+
// edition, so these shouldn't be checked.
23+
if is_package && !is_2021 {
2224
tidy_error!(
2325
bad,
2426
"{} doesn't have `edition = \"2021\"` on a separate line",

0 commit comments

Comments
 (0)