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> {
1239
1239
if let FixableWarnings :: Positive ( fixable) = count. fixable {
1240
1240
// `cargo fix` doesnt have an option for custom builds
1241
1241
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 = {
1243
1250
let named = unit. target . description_named ( ) ;
1244
1251
// if its a lib we need to add the package to fix
1245
1252
if unit. target . is_lib ( ) {
@@ -1251,16 +1258,16 @@ impl<'cfg> DrainState<'cfg> {
1251
1258
if unit. mode . is_rustc_test ( )
1252
1259
&& !( unit. target . is_test ( ) || unit. target . is_bench ( ) )
1253
1260
{
1254
- command . push_str ( " --tests" ) ;
1261
+ args . push_str ( " --tests" ) ;
1255
1262
}
1256
1263
let mut suggestions = format ! ( "{} suggestion" , fixable) ;
1257
1264
if fixable > 1 {
1258
1265
suggestions. push_str ( "s" )
1259
1266
}
1260
1267
drop ( write ! (
1261
1268
message,
1262
- " (run `cargo fix --{}` to apply {})" ,
1263
- command, suggestions
1269
+ " (run `{} --{}` to apply {})" ,
1270
+ command, args , suggestions
1264
1271
) )
1265
1272
}
1266
1273
}
Original file line number Diff line number Diff line change @@ -508,3 +508,33 @@ error: no such command: `bluid`
508
508
)
509
509
. run ( ) ;
510
510
}
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