]> git.lizzy.rs Git - rust.git/blob - src/tools/tidy/src/edition.rs
Rollup merge of #102685 - nbdd0121:unwind, 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 crate::walk::{filter_dirs, walk};
4 use std::path::Path;
5
6 fn is_edition_2021(mut line: &str) -> bool {
7     line = line.trim();
8     line == "edition = \"2021\""
9 }
10
11 pub fn check(path: &Path, bad: &mut bool) {
12     walk(
13         path,
14         &mut |path| filter_dirs(path) || path.ends_with("src/test"),
15         &mut |entry, contents| {
16             let file = entry.path();
17             let filename = file.file_name().unwrap();
18             if filename != "Cargo.toml" {
19                 return;
20             }
21
22             let is_2021 = contents.lines().any(is_edition_2021);
23             if !is_2021 {
24                 tidy_error!(
25                     bad,
26                     "{} doesn't have `edition = \"2021\"` on a separate line",
27                     file.display()
28                 );
29             }
30         },
31     );
32 }