Adjust tidy edition lint to force 2021

This has a few exceptions today (library crates, a few submodules), but is
mostly accurate.
This commit is contained in:
Noah Lev 2021-09-18 17:31:54 -07:00 committed by Mark Rousskov
parent c746be2219
commit 662daee658

View File

@ -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()
);
}
}
},
);