1
- //! Tidy check to ensure that crate `edition` is '2018'
1
+ //! Tidy check to ensure that crate `edition` is '2018' or '2021'.
2
2
3
3
use std:: path:: Path ;
4
4
5
5
fn is_edition_2018 ( mut line : & str ) -> bool {
6
6
line = line. trim ( ) ;
7
- line == "edition = \" 2018\" " || line == "edition = \' 2018\' "
7
+ line == "edition = \" 2018\" "
8
+ }
9
+
10
+ fn is_edition_2021 ( mut line : & str ) -> bool {
11
+ line = line. trim ( ) ;
12
+ line == "edition = \" 2021\" "
8
13
}
9
14
10
15
pub fn check ( path : & Path , bad : & mut bool ) {
@@ -13,17 +18,38 @@ pub fn check(path: &Path, bad: &mut bool) {
13
18
& mut |path| super :: filter_dirs ( path) || path. ends_with ( "src/test" ) ,
14
19
& mut |entry, contents| {
15
20
let file = entry. path ( ) ;
21
+ let filestr = file. to_string_lossy ( ) . replace ( "\\ " , "/" ) ;
16
22
let filename = file. file_name ( ) . unwrap ( ) ;
17
23
if filename != "Cargo.toml" {
18
24
return ;
19
25
}
20
- let has_edition = contents. lines ( ) . any ( is_edition_2018) ;
21
- if !has_edition {
22
- tidy_error ! (
23
- bad,
24
- "{} doesn't have `edition = \" 2018\" ` on a separate line" ,
25
- file. display( )
26
- ) ;
26
+
27
+ // Library crates are not yet ready to migrate to 2021.
28
+ //
29
+ // The reference and rustc-dev-guide are submodules, so are left at
30
+ // 2018 for now. They should be removed from this exception list
31
+ // when bumped.
32
+ if path. components ( ) . any ( |c| c. as_os_str ( ) == "library" )
33
+ || filestr. contains ( "src/doc/reference/style-check/Cargo.toml" )
34
+ || filestr. contains ( "src/doc/rustc-dev-guide/ci/date-check/Cargo.toml" )
35
+ {
36
+ let has = contents. lines ( ) . any ( is_edition_2018) ;
37
+ if !has {
38
+ tidy_error ! (
39
+ bad,
40
+ "{} doesn't have `edition = \" 2018\" ` on a separate line" ,
41
+ file. display( )
42
+ ) ;
43
+ }
44
+ } else {
45
+ let is_2021 = contents. lines ( ) . any ( is_edition_2021) ;
46
+ if !is_2021 {
47
+ tidy_error ! (
48
+ bad,
49
+ "{} doesn't have `edition = \" 2021\" ` on a separate line" ,
50
+ file. display( )
51
+ ) ;
52
+ }
27
53
}
28
54
} ,
29
55
) ;
0 commit comments