diff options
| author | Noah Lev <camelidcamel@gmail.com> | 2021-09-18 17:31:54 -0700 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2021-09-20 22:21:42 -0400 |
| commit | 662daee6582c84cdb7fc9b053bba4fb211a73299 (patch) | |
| tree | 79a996bafc863324dcc3bd81b85e2d4c076a0eaf | |
| parent | c746be2219fac78e5adad715082dedeb2d737f0d (diff) | |
| download | rust-662daee6582c84cdb7fc9b053bba4fb211a73299.tar.gz rust-662daee6582c84cdb7fc9b053bba4fb211a73299.zip | |
Adjust tidy edition lint to force 2021
This has a few exceptions today (library crates, a few submodules), but is mostly accurate.
| -rw-r--r-- | src/tools/tidy/src/edition.rs | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/src/tools/tidy/src/edition.rs b/src/tools/tidy/src/edition.rs index 283c43e325c..b5e9ceddbaf 100644 --- a/src/tools/tidy/src/edition.rs +++ b/src/tools/tidy/src/edition.rs @@ -1,10 +1,15 @@ -//! Tidy check to ensure that crate `edition` is '2018' +//! Tidy check to ensure that crate `edition` is '2018' or '2021'. use std::path::Path; fn is_edition_2018(mut line: &str) -> bool { line = line.trim(); - line == "edition = \"2018\"" || line == "edition = \'2018\'" + line == "edition = \"2018\"" +} + +fn is_edition_2021(mut line: &str) -> bool { + line = line.trim(); + line == "edition = \"2021\"" } pub fn check(path: &Path, bad: &mut bool) { @@ -13,17 +18,38 @@ pub fn check(path: &Path, bad: &mut bool) { &mut |path| super::filter_dirs(path) || path.ends_with("src/test"), &mut |entry, contents| { let file = entry.path(); + let filestr = file.to_string_lossy().replace("\\", "/"); let filename = file.file_name().unwrap(); if filename != "Cargo.toml" { return; } - let has_edition = contents.lines().any(is_edition_2018); - if !has_edition { - tidy_error!( - bad, - "{} doesn't have `edition = \"2018\"` on a separate line", - file.display() - ); + + // Library crates are not yet ready to migrate to 2021. + // + // The reference and rustc-dev-guide are submodules, so are left at + // 2018 for now. They should be removed from this exception list + // when bumped. + if path.components().any(|c| c.as_os_str() == "library") + || filestr.contains("src/doc/reference/style-check/Cargo.toml") + || filestr.contains("src/doc/rustc-dev-guide/ci/date-check/Cargo.toml") + { + let has = contents.lines().any(is_edition_2018); + if !has { + tidy_error!( + bad, + "{} doesn't have `edition = \"2018\"` on a separate line", + file.display() + ); + } + } else { + let is_2021 = contents.lines().any(is_edition_2021); + if !is_2021 { + tidy_error!( + bad, + "{} doesn't have `edition = \"2021\"` on a separate line", + file.display() + ); + } } }, ); |
