]> git.proxmox.com Git - rustc.git/blame - src/tools/tidy/src/edition.rs
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / src / tools / tidy / src / edition.rs
CommitLineData
416331ca 1//! Tidy check to ensure that crate `edition` is '2018'
416331ca
XL
2
3use std::path::Path;
4
5fn filter_dirs(path: &Path) -> bool {
6 // FIXME: just use super::filter_dirs after the submodules are updated.
7 if super::filter_dirs(path) {
8 return true;
9 }
10 let skip = [
11 "src/doc/book/second-edition",
12 "src/doc/book/2018-edition",
13 "src/doc/book/ci/stable-check",
14 "src/doc/reference/stable-check",
15 ];
16 skip.iter().any(|p| path.ends_with(p))
17}
18
19fn is_edition_2018(mut line: &str) -> bool {
20 line = line.trim();
21 line == "edition = \"2018\"" || line == "edition = \'2018\'"
22}
23
24pub fn check(path: &Path, bad: &mut bool) {
25 super::walk(
26 path,
27 &mut |path| filter_dirs(path) || path.ends_with("src/test"),
28 &mut |entry, contents| {
29 let file = entry.path();
30 let filename = file.file_name().unwrap();
31 if filename != "Cargo.toml" {
32 return;
33 }
34 let has_edition = contents.lines().any(is_edition_2018);
35 if !has_edition {
36 tidy_error!(
37 bad,
38 "{} doesn't have `edition = \"2018\"` on a separate line",
39 file.display()
40 );
41 }
42 },
43 );
44}