]> git.lizzy.rs Git - rust.git/blob - src/tools/tidy/src/edition.rs
Auto merge of #93176 - danielhenrymantilla:stack-pinning-macro, r=m-ou-se
[rust.git] / src / tools / tidy / src / edition.rs
1 //! Tidy check to ensure that crate `edition` is '2018' or '2021'.
2
3 use std::path::Path;
4
5 fn is_edition_2021(mut line: &str) -> bool {
6     line = line.trim();
7     line == "edition = \"2021\""
8 }
9
10 pub fn check(path: &Path, bad: &mut bool) {
11     super::walk(
12         path,
13         &mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
14         &mut |entry, contents| {
15             let file = entry.path();
16             let filename = file.file_name().unwrap();
17             if filename != "Cargo.toml" {
18                 return;
19             }
20
21             let is_2021 = contents.lines().any(is_edition_2021);
22             if !is_2021 {
23                 tidy_error!(
24                     bad,
25                     "{} doesn't have `edition = \"2021\"` on a separate line",
26                     file.display()
27                 );
28             }
29         },
30     );
31 }