summaryrefslogtreecommitdiffstats
path: root/src/tools/tidy/src/edition.rs
blob: b0abee459869cc5d5b4981c2fe44f660f72a231f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//! Tidy check to ensure that crate `edition` is '2018' or '2021'.

use std::path::Path;

fn is_edition_2021(mut line: &str) -> bool {
    line = line.trim();
    line == "edition = \"2021\""
}

pub fn check(path: &Path, bad: &mut bool) {
    super::walk(
        path,
        &mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
        &mut |entry, contents| {
            let file = entry.path();
            let filename = file.file_name().unwrap();
            if filename != "Cargo.toml" {
                return;
            }

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