File tree 2 files changed +34
-2
lines changed
2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 1
1
use command_prelude:: * ;
2
2
3
- use cargo:: ops;
3
+ use cargo:: ops:: { self , CompileFilter , FilterRule } ;
4
4
5
5
pub fn cli ( ) -> App {
6
6
subcommand ( "fix" )
@@ -106,9 +106,26 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
106
106
}
107
107
} ;
108
108
let mode = CompileMode :: Check { test } ;
109
+
110
+ // Unlike other commands default `cargo fix` to all targets to fix as much
111
+ // code as we can.
112
+ let mut opts = args. compile_options ( config, mode) ?;
113
+ match opts. filter {
114
+ CompileFilter :: Default { .. } => {
115
+ opts. filter = CompileFilter :: Only {
116
+ all_targets : true ,
117
+ lib : true ,
118
+ bins : FilterRule :: All ,
119
+ examples : FilterRule :: All ,
120
+ benches : FilterRule :: All ,
121
+ tests : FilterRule :: All ,
122
+ } ;
123
+ }
124
+ _ => { }
125
+ }
109
126
ops:: fix ( & ws, & mut ops:: FixOptions {
110
127
edition : args. value_of ( "edition" ) ,
111
- compile_opts : args . compile_options ( config , mode ) ? ,
128
+ compile_opts : opts ,
112
129
allow_dirty : args. is_present ( "allow-dirty" ) ,
113
130
allow_no_vcs : args. is_present ( "allow-no-vcs" ) ,
114
131
broken_code : args. is_present ( "broken-code" ) ,
Original file line number Diff line number Diff line change @@ -843,3 +843,18 @@ fn does_not_warn_about_dirty_ignored_files() {
843
843
execs ( ) . with_status ( 0 ) ,
844
844
) ;
845
845
}
846
+
847
+ #[ test]
848
+ fn fix_all_targets_by_default ( ) {
849
+ let p = project ( )
850
+ . file ( "src/lib.rs" , "pub fn foo() { let mut x = 3; drop(x); }" )
851
+ . file ( "tests/foo.rs" , "pub fn foo() { let mut x = 3; drop(x); }" )
852
+ . build ( ) ;
853
+ assert_that (
854
+ p. cargo ( "fix --allow-no-vcs" )
855
+ . env ( "__CARGO_FIX_YOLO" , "1" ) ,
856
+ execs ( ) . with_status ( 0 ) ,
857
+ ) ;
858
+ assert ! ( !p. read_file( "src/lib.rs" ) . contains( "let mut x" ) ) ;
859
+ assert ! ( !p. read_file( "tests/foo.rs" ) . contains( "let mut x" ) ) ;
860
+ }
You can’t perform that action at this time.
0 commit comments