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 +63
-0
lines changed Expand file tree Collapse file tree 3 files changed +63
-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 warnings 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 ( "RUSTFLAGS" ) . unwrap_or_else ( || "" . into ( ) ) ;
92
+ rustc_flags. push ( "-W rust-2018-breakage" ) ;
93
+ cmd. env ( "RUSTFLAGS" , & 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(rust_2018_preview)]
17
+
18
+ mod foo {
19
+ pub const FOO: &str = "fooo";
20
+ }
21
+
22
+ mod bar {
23
+ use ::foo::FOO;
24
+ }
25
+
26
+ fn main() {
27
+ let x = ::foo::FOO;
28
+ }
29
+ "# ,
30
+ )
31
+ . build ( ) ;
32
+
33
+ let stderr = "\
34
+ [CHECKING] foo v0.1.0 (CWD)
35
+ [FIXING] src/lib.rs (2 fixes)
36
+ [FINISHED] dev [unoptimized + debuginfo]
37
+ " ;
38
+ p. expect_cmd ( "cargo-fix fix --prepare-for 2018" )
39
+ . stdout ( "" )
40
+ . stderr ( stderr)
41
+ . run ( ) ;
42
+
43
+ println ! ( "{}" , p. read( "src/lib.rs" ) ) ;
44
+ assert ! ( p. read( "src/lib.rs" ) . contains( "use crate::foo::FOO;" ) ) ;
45
+ assert ! ( p. read( "src/lib.rs" ) . contains( "let x = crate::foo::FOO;" ) ) ;
46
+ }
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