@@ -62,7 +62,7 @@ struct ClippyCmd {
6262 unstable_options : bool ,
6363 cargo_subcommand : & ' static str ,
6464 args : Vec < String > ,
65- clippy_args : String ,
65+ clippy_args : Vec < String > ,
6666}
6767
6868impl ClippyCmd {
@@ -99,7 +99,10 @@ impl ClippyCmd {
9999 args. insert ( 0 , "+nightly" . to_string ( ) ) ;
100100 }
101101
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+ }
103106
104107 ClippyCmd {
105108 unstable_options,
@@ -147,10 +150,15 @@ impl ClippyCmd {
147150
148151 fn into_std_cmd ( self ) -> Command {
149152 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 ( ) ;
150158
151159 cmd. env ( self . path_env ( ) , Self :: path ( ) )
152160 . envs ( ClippyCmd :: target_dir ( ) )
153- . env ( "CLIPPY_ARGS" , self . clippy_args )
161+ . env ( "CLIPPY_ARGS" , clippy_args)
154162 . arg ( self . cargo_subcommand )
155163 . args ( & self . args ) ;
156164
@@ -201,6 +209,24 @@ mod tests {
201209 assert ! ( cmd. args. iter( ) . any( |arg| arg. ends_with( "unstable-options" ) ) ) ;
202210 }
203211
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+
204230 #[ test]
205231 fn check ( ) {
206232 let args = "cargo clippy" . split_whitespace ( ) . map ( ToString :: to_string) ;
0 commit comments