11use command_prelude:: * ;
22
3- use cargo:: ops;
3+ use cargo:: ops:: { self , CompileFilter , FilterRule } ;
44
55pub fn cli ( ) -> App {
66 subcommand ( "fix" )
@@ -37,10 +37,24 @@ pub fn cli() -> App {
3737 )
3838 . arg (
3939 Arg :: with_name ( "edition" )
40+ . long ( "edition" )
41+ . help ( "Fix in preparation for the next edition" ) ,
42+ )
43+ . arg (
44+ // This is a deprecated argument, we'll want to phase it out
45+ // eventually.
46+ Arg :: with_name ( "prepare-for" )
4047 . long ( "prepare-for" )
4148 . help ( "Fix warnings in preparation of an edition upgrade" )
4249 . takes_value ( true )
43- . possible_values ( & [ "2018" ] ) ,
50+ . possible_values ( & [ "2018" ] )
51+ . conflicts_with ( "edition" )
52+ . hidden ( true ) ,
53+ )
54+ . arg (
55+ Arg :: with_name ( "idioms" )
56+ . long ( "edition-idioms" )
57+ . help ( "Fix warnings to migrate to the idioms of an edition" )
4458 )
4559 . arg (
4660 Arg :: with_name ( "allow-no-vcs" )
@@ -67,22 +81,16 @@ remaining warnings will be displayed when the check process is finished. For
6781example if you'd like to prepare for the 2018 edition, you can do so by
6882executing:
6983
70- cargo fix --prepare-for 2018
71-
72- Note that this is not guaranteed to fix all your code as it only fixes code that
73- `cargo check` would otherwise compile. For example unit tests are left out
74- from this command, but they can be checked with:
75-
76- cargo fix --prepare-for 2018 --all-targets
84+ cargo fix --edition
7785
7886which behaves the same as `cargo check --all-targets`. Similarly if you'd like
7987to fix code for different platforms you can do:
8088
81- cargo fix --prepare-for 2018 --target x86_64-pc-windows-gnu
89+ cargo fix --edition --target x86_64-pc-windows-gnu
8290
8391or if your crate has optional features:
8492
85- cargo fix --prepare-for 2018 --no-default-features --features foo
93+ cargo fix --edition --no-default-features --features foo
8694
8795If you encounter any problems with `cargo fix` or otherwise have any questions
8896or feature requests please don't hesitate to file an issue at
@@ -106,9 +114,25 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
106114 }
107115 } ;
108116 let mode = CompileMode :: Check { test } ;
117+
118+ // Unlike other commands default `cargo fix` to all targets to fix as much
119+ // code as we can.
120+ let mut opts = args. compile_options ( config, mode) ?;
121+ if let CompileFilter :: Default { .. } = opts. filter {
122+ opts. filter = CompileFilter :: Only {
123+ all_targets : true ,
124+ lib : true ,
125+ bins : FilterRule :: All ,
126+ examples : FilterRule :: All ,
127+ benches : FilterRule :: All ,
128+ tests : FilterRule :: All ,
129+ }
130+ }
109131 ops:: fix ( & ws, & mut ops:: FixOptions {
110- edition : args. value_of ( "edition" ) ,
111- compile_opts : args. compile_options ( config, mode) ?,
132+ edition : args. is_present ( "edition" ) ,
133+ prepare_for : args. value_of ( "prepare-for" ) ,
134+ idioms : args. is_present ( "idioms" ) ,
135+ compile_opts : opts,
112136 allow_dirty : args. is_present ( "allow-dirty" ) ,
113137 allow_no_vcs : args. is_present ( "allow-no-vcs" ) ,
114138 broken_code : args. is_present ( "broken-code" ) ,
0 commit comments