@@ -189,14 +189,25 @@ impl CrateSource {
189
189
create_dirs ( & krate_download_dir, & extract_dir) ;
190
190
191
191
let krate_file_path = krate_download_dir. join ( format ! ( "{name}-{version}.crate.tar.gz" ) ) ;
192
- // don't download/extract if we already have done so
192
+ // don't download if we already have done so
193
193
if !krate_file_path. is_file ( ) {
194
194
// create a file path to download and write the crate data into
195
195
let mut krate_dest = std:: fs:: File :: create ( & krate_file_path) . unwrap ( ) ;
196
196
let mut krate_req = get ( & url) . unwrap ( ) . into_reader ( ) ;
197
197
// copy the crate into the file
198
198
std:: io:: copy ( & mut krate_req, & mut krate_dest) . unwrap ( ) ;
199
+ }
199
200
201
+ // if the source code was altered (previous use of `--fix`), we need to restore the crate
202
+ // to its original state by re-extracting it
203
+ if !extracted_krate_dir. exists ( )
204
+ || extracted_krate_dir. metadata ( ) . map_or ( false , |metadata| {
205
+ metadata. created ( ) . map_or ( false , |created| {
206
+ metadata. modified ( ) . map_or ( false , |modified| created != modified)
207
+ } )
208
+ } )
209
+ {
210
+ debug ! ( "extracting {} {}" , name, version) ;
200
211
// unzip the tarball
201
212
let ungz_tar = flate2:: read:: GzDecoder :: new ( std:: fs:: File :: open ( & krate_file_path) . unwrap ( ) ) ;
202
213
// extract the tar archive
@@ -338,7 +349,9 @@ impl Crate {
338
349
let shared_target_dir = clippy_project_root ( ) . join ( "target/lintcheck/shared_target_dir" ) ;
339
350
340
351
let mut cargo_clippy_args = if config. fix {
341
- vec ! [ "--fix" , "--" ]
352
+ // need to pass `clippy` arg even if already feeding `cargo-clippy`
353
+ // see https://github.com/rust-lang/rust-clippy/pull/9461
354
+ vec ! [ "clippy" , "--fix" , "--allow-no-vcs" , "--" ]
342
355
} else {
343
356
vec ! [ "--" , "--message-format=json" , "--" ]
344
357
} ;
@@ -348,16 +361,19 @@ impl Crate {
348
361
for opt in options {
349
362
clippy_args. push ( opt) ;
350
363
}
351
- } else {
352
- clippy_args. extend ( [ "-Wclippy::pedantic" , "-Wclippy::cargo" ] ) ;
353
364
}
354
365
355
- if lint_filter. is_empty ( ) {
356
- clippy_args. push ( "--cap-lints=warn" ) ;
366
+ // cap-lints flag is ignored when using `clippy --fix` for now
367
+ // So it needs to be passed directly to rustc
368
+ // see https://github.com/rust-lang/rust-clippy/issues/9703
369
+ let rustc_flags = if lint_filter. is_empty ( ) {
370
+ clippy_args. extend ( [ "-Wclippy::pedantic" , "-Wclippy::cargo" ] ) ;
371
+ "--cap-lints=warn" . to_string ( )
357
372
} else {
358
- clippy_args. push ( "--cap-lints=allow" ) ;
359
- clippy_args. extend ( lint_filter. iter ( ) . map ( std:: string:: String :: as_str) ) ;
360
- }
373
+ let mut lint_filter_buf = lint_filter. clone ( ) ;
374
+ lint_filter_buf. push ( "--cap-lints=allow" . to_string ( ) ) ;
375
+ lint_filter_buf. join ( " " )
376
+ } ;
361
377
362
378
if let Some ( server) = server {
363
379
let target = shared_target_dir. join ( "recursive" ) ;
@@ -396,6 +412,7 @@ impl Crate {
396
412
let all_output = Command :: new ( & cargo_clippy_path)
397
413
// use the looping index to create individual target dirs
398
414
. env ( "CARGO_TARGET_DIR" , shared_target_dir. join ( format ! ( "_{thread_index:?}" ) ) )
415
+ . env ( "RUSTFLAGS" , rustc_flags)
399
416
. args ( & cargo_clippy_args)
400
417
. current_dir ( & self . path )
401
418
. output ( )
0 commit comments