This repository was archived by the owner on Nov 24, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,13 @@ pub fn run() -> Result<(), Error> {
33
33
Arg :: with_name ( "broken-code" )
34
34
. long ( "broken-code" )
35
35
. help ( "Fix code even if it already has compiler errors" ) ,
36
+ )
37
+ . arg (
38
+ Arg :: with_name ( "edition" )
39
+ . long ( "prepare-for" )
40
+ . help ( "Fix warnigns in preparation of an edition upgrade" )
41
+ . takes_value ( true )
42
+ . possible_values ( & [ "2018" ] ) ,
36
43
) ,
37
44
)
38
45
. get_matches ( ) ;
@@ -77,6 +84,15 @@ pub fn run() -> Result<(), Error> {
77
84
cmd. env ( "RUSTC_ORIGINAL" , rustc) ;
78
85
}
79
86
87
+ // Trigger edition-upgrade mode. Currently only supports the 2018 edition.
88
+ info ! ( "edition upgrade? {:?}" , matches. value_of( "edition" ) ) ;
89
+ if let Some ( "2018" ) = matches. value_of ( "edition" ) {
90
+ info ! ( "edition upgrade!" ) ;
91
+ let mut rustc_flags = env:: var_os ( "RUSTC_FLAGS" ) . unwrap_or_else ( || "" . into ( ) ) ;
92
+ rustc_flags. push ( "-A warnings -W rust_2018_breakage" ) ;
93
+ cmd. env ( "RUSTC_FLAGS" , & rustc_flags) ;
94
+ }
95
+
80
96
// An now execute all of Cargo! This'll fix everything along the way.
81
97
//
82
98
// TODO: we probably want to do something fancy here like collect results
Original file line number Diff line number Diff line change
1
+ //! Test that we can use cargo-fix to upgrade our code to work with the 2018
2
+ //! edition.
3
+ //!
4
+ //! We'll trigger the `absolute_path_starting_with_module` lint which should
5
+ //! transform a `use ::foo;` where `foo` is local to `use crate::foo;`.
6
+
7
+ use super :: project;
8
+
9
+ #[ test]
10
+ fn prepare_for_2018 ( ) {
11
+ let p = project ( )
12
+ . file (
13
+ "src/lib.rs" ,
14
+ r#"
15
+ #![allow(unused)]
16
+ #![feature(crate_in_paths)]
17
+ #![warn(absolute_path_starting_with_module)]
18
+
19
+ mod foo {
20
+ pub const FOO: &str = "fooo";
21
+ }
22
+
23
+ mod bar {
24
+ use ::foo::FOO;
25
+ }
26
+
27
+ fn main() {
28
+ let x = ::foo::FOO;
29
+ }
30
+ "# ,
31
+ )
32
+ . build ( ) ;
33
+
34
+ let stderr = "\
35
+ [CHECKING] foo v0.1.0 (CWD)
36
+ [FIXING] src/lib.rs (2 fixes)
37
+ [FINISHED] dev [unoptimized + debuginfo]
38
+ " ;
39
+ p. expect_cmd ( "cargo-fix fix --prepare-for 2018" )
40
+ . stdout ( "" )
41
+ . stderr ( stderr)
42
+ . run ( ) ;
43
+
44
+ println ! ( "{}" , p. read( "src/lib.rs" ) ) ;
45
+ assert ! ( p. read( "src/lib.rs" ) . contains( "use crate::foo::FOO;" ) ) ;
46
+ assert ! ( p. read( "src/lib.rs" ) . contains( "let x = crate::foo::FOO;" ) ) ;
47
+ }
Original file line number Diff line number Diff line change @@ -318,6 +318,7 @@ fn diff(expected: &str, actual: &str) {
318
318
mod broken_build;
319
319
mod broken_lints;
320
320
mod dependencies;
321
+ mod edition_upgrade;
321
322
mod smoke;
322
323
mod subtargets;
323
324
mod warnings;
You can’t perform that action at this time.
0 commit comments