]>
Commit | Line | Data |
---|---|---|
416331ca | 1 | //! Tidy check to ensure that crate `edition` is '2018' |
416331ca XL |
2 | |
3 | use std::path::Path; | |
4 | ||
5 | fn 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 | ||
19 | fn is_edition_2018(mut line: &str) -> bool { | |
20 | line = line.trim(); | |
21 | line == "edition = \"2018\"" || line == "edition = \'2018\'" | |
22 | } | |
23 | ||
24 | pub 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 | } |