1- //! Tidy check to ensure that crate `edition` is '2018'
1+ //! Tidy check to ensure that crate `edition` is '2018' or '2021'.
22
33use std:: path:: Path ;
44
55fn is_edition_2018 ( mut line : & str ) -> bool {
66 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\" "
813}
914
1015pub fn check ( path : & Path , bad : & mut bool ) {
@@ -13,17 +18,38 @@ pub fn check(path: &Path, bad: &mut bool) {
1318 & mut |path| super :: filter_dirs ( path) || path. ends_with ( "src/test" ) ,
1419 & mut |entry, contents| {
1520 let file = entry. path ( ) ;
21+ let filestr = file. to_string_lossy ( ) . replace ( "\\ " , "/" ) ;
1622 let filename = file. file_name ( ) . unwrap ( ) ;
1723 if filename != "Cargo.toml" {
1824 return ;
1925 }
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+ }
2753 }
2854 } ,
2955 ) ;
0 commit comments