File tree Expand file tree Collapse file tree 2 files changed +41
-4
lines changed Expand file tree Collapse file tree 2 files changed +41
-4
lines changed Original file line number Diff line number Diff line change @@ -1239,7 +1239,14 @@ impl<'cfg> DrainState<'cfg> {
12391239 if let FixableWarnings :: Positive ( fixable) = count. fixable {
12401240 // `cargo fix` doesnt have an option for custom builds
12411241 if !unit. target . is_custom_build ( ) {
1242- let mut command = {
1242+ // To make sure the correct command is shown for `clippy` we
1243+ // check if `CLIPPY_ARGS` is set as `clippy` sets this when ran
1244+ let command = if config. env ( ) . get ( "CLIPPY_ARGS" ) . is_some ( ) {
1245+ "cargo clippy --fix"
1246+ } else {
1247+ "cargo fix"
1248+ } ;
1249+ let mut args = {
12431250 let named = unit. target . description_named ( ) ;
12441251 // if its a lib we need to add the package to fix
12451252 if unit. target . is_lib ( ) {
@@ -1251,16 +1258,16 @@ impl<'cfg> DrainState<'cfg> {
12511258 if unit. mode . is_rustc_test ( )
12521259 && !( unit. target . is_test ( ) || unit. target . is_bench ( ) )
12531260 {
1254- command . push_str ( " --tests" ) ;
1261+ args . push_str ( " --tests" ) ;
12551262 }
12561263 let mut suggestions = format ! ( "{} suggestion" , fixable) ;
12571264 if fixable > 1 {
12581265 suggestions. push_str ( "s" )
12591266 }
12601267 drop ( write ! (
12611268 message,
1262- " (run `cargo fix --{}` to apply {})" ,
1263- command, suggestions
1269+ " (run `{} --{}` to apply {})" ,
1270+ command, args , suggestions
12641271 ) )
12651272 }
12661273 }
Original file line number Diff line number Diff line change @@ -508,3 +508,33 @@ error: no such command: `bluid`
508508 )
509509 . run ( ) ;
510510}
511+
512+ #[ cargo_test]
513+ fn check_fixable_warning_for_clippy ( ) {
514+ let foo = project ( )
515+ . file (
516+ "Cargo.toml" ,
517+ r#"
518+ [package]
519+ name = "foo"
520+ version = "0.0.1"
521+ "# ,
522+ )
523+ // We don't want to show a warning that is `clippy`
524+ // specific since it could change in the future
525+ . file ( "src/lib.rs" , "use std::io;" )
526+ . build ( ) ;
527+
528+ // To ensure it uses the version of `cargo` we currently
529+ // test against, we prepend build artifacts directory
530+ // to `$PATH`
531+ let cargo = cargo_exe ( ) . canonicalize ( ) . unwrap ( ) ;
532+ let mut path = path ( ) ;
533+ path. insert ( 0 , cargo. parent ( ) . unwrap ( ) . into ( ) ) ;
534+ let path = env:: join_paths ( path. iter ( ) ) . unwrap ( ) ;
535+ foo. cargo ( "clippy" )
536+ . env ( "PATH" , & path)
537+ . masquerade_as_nightly_cargo ( & [ "auto-fix note" ] )
538+ . with_stderr_contains ( "[..] (run `cargo clippy --fix --lib -p foo` to apply 1 suggestion)" )
539+ . run ( ) ;
540+ }
You can’t perform that action at this time.
0 commit comments