@@ -62,7 +62,7 @@ struct ClippyCmd {
62
62
unstable_options : bool ,
63
63
cargo_subcommand : & ' static str ,
64
64
args : Vec < String > ,
65
- clippy_args : String ,
65
+ clippy_args : Vec < String > ,
66
66
}
67
67
68
68
impl ClippyCmd {
@@ -99,7 +99,10 @@ impl ClippyCmd {
99
99
args. insert ( 0 , "+nightly" . to_string ( ) ) ;
100
100
}
101
101
102
- let clippy_args: String = old_args. map ( |arg| format ! ( "{}__CLIPPY_HACKERY__" , arg) ) . collect ( ) ;
102
+ let mut clippy_args: Vec < String > = old_args. collect ( ) ;
103
+ if cargo_subcommand == "fix" && !clippy_args. iter ( ) . any ( |arg| arg == "--no-deps" ) {
104
+ clippy_args. push ( "--no-deps" . into ( ) ) ;
105
+ }
103
106
104
107
ClippyCmd {
105
108
unstable_options,
@@ -147,10 +150,15 @@ impl ClippyCmd {
147
150
148
151
fn into_std_cmd ( self ) -> Command {
149
152
let mut cmd = Command :: new ( "cargo" ) ;
153
+ let clippy_args: String = self
154
+ . clippy_args
155
+ . iter ( )
156
+ . map ( |arg| format ! ( "{}__CLIPPY_HACKERY__" , arg) )
157
+ . collect ( ) ;
150
158
151
159
cmd. env ( self . path_env ( ) , Self :: path ( ) )
152
160
. envs ( ClippyCmd :: target_dir ( ) )
153
- . env ( "CLIPPY_ARGS" , self . clippy_args )
161
+ . env ( "CLIPPY_ARGS" , clippy_args)
154
162
. arg ( self . cargo_subcommand )
155
163
. args ( & self . args ) ;
156
164
@@ -201,6 +209,24 @@ mod tests {
201
209
assert ! ( cmd. args. iter( ) . any( |arg| arg. ends_with( "unstable-options" ) ) ) ;
202
210
}
203
211
212
+ #[ test]
213
+ fn fix_implies_no_deps ( ) {
214
+ let args = "cargo clippy --fix -Zunstable-options"
215
+ . split_whitespace ( )
216
+ . map ( ToString :: to_string) ;
217
+ let cmd = ClippyCmd :: new ( args) ;
218
+ assert ! ( cmd. clippy_args. iter( ) . any( |arg| arg == "--no-deps" ) ) ;
219
+ }
220
+
221
+ #[ test]
222
+ fn no_deps_not_duplicated_with_fix ( ) {
223
+ let args = "cargo clippy --fix -Zunstable-options -- --no-deps"
224
+ . split_whitespace ( )
225
+ . map ( ToString :: to_string) ;
226
+ let cmd = ClippyCmd :: new ( args) ;
227
+ assert_eq ! ( cmd. clippy_args. iter( ) . filter( |arg| * arg == "--no-deps" ) . count( ) , 1 ) ;
228
+ }
229
+
204
230
#[ test]
205
231
fn check ( ) {
206
232
let args = "cargo clippy" . split_whitespace ( ) . map ( ToString :: to_string) ;
0 commit comments