]>
Commit | Line | Data |
---|---|---|
c295e0f8 | 1 | //! Tidy check to ensure that crate `edition` is '2018' or '2021'. |
416331ca XL |
2 | |
3 | use std::path::Path; | |
4 | ||
416331ca XL |
5 | fn is_edition_2018(mut line: &str) -> bool { |
6 | line = line.trim(); | |
c295e0f8 XL |
7 | line == "edition = \"2018\"" |
8 | } | |
9 | ||
10 | fn is_edition_2021(mut line: &str) -> bool { | |
11 | line = line.trim(); | |
12 | line == "edition = \"2021\"" | |
416331ca XL |
13 | } |
14 | ||
15 | pub fn check(path: &Path, bad: &mut bool) { | |
16 | super::walk( | |
17 | path, | |
5869c6ff | 18 | &mut |path| super::filter_dirs(path) || path.ends_with("src/test"), |
416331ca XL |
19 | &mut |entry, contents| { |
20 | let file = entry.path(); | |
21 | let filename = file.file_name().unwrap(); | |
22 | if filename != "Cargo.toml" { | |
23 | return; | |
24 | } | |
c295e0f8 XL |
25 | |
26 | // Library crates are not yet ready to migrate to 2021. | |
3c0e092e | 27 | if path.components().any(|c| c.as_os_str() == "library") { |
c295e0f8 XL |
28 | let has = contents.lines().any(is_edition_2018); |
29 | if !has { | |
30 | tidy_error!( | |
31 | bad, | |
32 | "{} doesn't have `edition = \"2018\"` on a separate line", | |
33 | file.display() | |
34 | ); | |
35 | } | |
36 | } else { | |
37 | let is_2021 = contents.lines().any(is_edition_2021); | |
38 | if !is_2021 { | |
39 | tidy_error!( | |
40 | bad, | |
41 | "{} doesn't have `edition = \"2021\"` on a separate line", | |
42 | file.display() | |
43 | ); | |
44 | } | |
416331ca XL |
45 | } |
46 | }, | |
47 | ); | |
48 | } |