@@ -116,12 +116,13 @@ impl ClippyWarning {
116
116
117
117
let span = diag. spans . into_iter ( ) . find ( |span| span. is_primary ) ?;
118
118
119
- let file = match Path :: new ( & span. file_name ) . strip_prefix ( env ! ( "CARGO_HOME" ) ) {
120
- Ok ( stripped) => format ! ( "$CARGO_HOME/{}" , stripped. display( ) ) ,
121
- Err ( _) => format ! (
119
+ let file = if let Ok ( stripped) = Path :: new ( & span. file_name ) . strip_prefix ( env ! ( "CARGO_HOME" ) ) {
120
+ format ! ( "$CARGO_HOME/{}" , stripped. display( ) )
121
+ } else {
122
+ format ! (
122
123
"target/lintcheck/sources/{}-{}/{}" ,
123
124
crate_name, crate_version, span. file_name
124
- ) ,
125
+ )
125
126
} ;
126
127
127
128
Some ( Self {
@@ -154,6 +155,7 @@ impl ClippyWarning {
154
155
}
155
156
}
156
157
158
+ #[ allow( clippy:: result_large_err) ]
157
159
fn get ( path : & str ) -> Result < ureq:: Response , ureq:: Error > {
158
160
const MAX_RETRIES : u8 = 4 ;
159
161
let mut retries = 0 ;
@@ -165,7 +167,7 @@ fn get(path: &str) -> Result<ureq::Response, ureq::Error> {
165
167
Err ( e) => return Err ( e) ,
166
168
}
167
169
eprintln ! ( "retrying in {retries} seconds..." ) ;
168
- thread:: sleep ( Duration :: from_secs ( retries as u64 ) ) ;
170
+ thread:: sleep ( Duration :: from_secs ( u64:: from ( retries ) ) ) ;
169
171
retries += 1 ;
170
172
}
171
173
}
@@ -232,7 +234,7 @@ impl CrateSource {
232
234
. expect ( "Failed to clone git repo!" )
233
235
. success ( )
234
236
{
235
- eprintln ! ( "Failed to clone {url} into {}" , repo_path. display( ) )
237
+ eprintln ! ( "Failed to clone {url} into {}" , repo_path. display( ) ) ;
236
238
}
237
239
}
238
240
// check out the commit/branch/whatever
@@ -245,7 +247,7 @@ impl CrateSource {
245
247
. expect ( "Failed to check out commit" )
246
248
. success ( )
247
249
{
248
- eprintln ! ( "Failed to checkout {commit} of repo at {}" , repo_path. display( ) )
250
+ eprintln ! ( "Failed to checkout {commit} of repo at {}" , repo_path. display( ) ) ;
249
251
}
250
252
251
253
Crate {
@@ -256,6 +258,12 @@ impl CrateSource {
256
258
}
257
259
} ,
258
260
CrateSource :: Path { name, path, options } => {
261
+ fn is_cache_dir ( entry : & DirEntry ) -> bool {
262
+ std:: fs:: read ( entry. path ( ) . join ( "CACHEDIR.TAG" ) )
263
+ . map ( |x| x. starts_with ( b"Signature: 8a477f597d28d172789f06886806bc55" ) )
264
+ . unwrap_or ( false )
265
+ }
266
+
259
267
// copy path into the dest_crate_root but skip directories that contain a CACHEDIR.TAG file.
260
268
// The target/ directory contains a CACHEDIR.TAG file so it is the most commonly skipped directory
261
269
// as a result of this filter.
@@ -267,12 +275,6 @@ impl CrateSource {
267
275
268
276
println ! ( "Copying {path:?} to {dest_crate_root:?}" ) ;
269
277
270
- fn is_cache_dir ( entry : & DirEntry ) -> bool {
271
- std:: fs:: read ( entry. path ( ) . join ( "CACHEDIR.TAG" ) )
272
- . map ( |x| x. starts_with ( b"Signature: 8a477f597d28d172789f06886806bc55" ) )
273
- . unwrap_or ( false )
274
- }
275
-
276
278
for entry in WalkDir :: new ( path) . into_iter ( ) . filter_entry ( |e| !is_cache_dir ( e) ) {
277
279
let entry = entry. unwrap ( ) ;
278
280
let entry_path = entry. path ( ) ;
@@ -301,6 +303,7 @@ impl CrateSource {
301
303
impl Crate {
302
304
/// Run `cargo clippy` on the `Crate` and collect and return all the lint warnings that clippy
303
305
/// issued
306
+ #[ allow( clippy:: too_many_arguments) ]
304
307
fn run_clippy_lints (
305
308
& self ,
306
309
cargo_clippy_path : & Path ,
@@ -345,14 +348,14 @@ impl Crate {
345
348
clippy_args. push ( opt) ;
346
349
}
347
350
} else {
348
- clippy_args. extend ( [ "-Wclippy::pedantic" , "-Wclippy::cargo" ] )
351
+ clippy_args. extend ( [ "-Wclippy::pedantic" , "-Wclippy::cargo" ] ) ;
349
352
}
350
353
351
354
if lint_filter. is_empty ( ) {
352
355
clippy_args. push ( "--cap-lints=warn" ) ;
353
356
} else {
354
357
clippy_args. push ( "--cap-lints=allow" ) ;
355
- clippy_args. extend ( lint_filter. iter ( ) . map ( |filter| filter . as_str ( ) ) )
358
+ clippy_args. extend ( lint_filter. iter ( ) . map ( std :: string :: String :: as_str) ) ;
356
359
}
357
360
358
361
if let Some ( server) = server {
@@ -463,7 +466,7 @@ fn read_crates(toml_path: &Path) -> (Vec<CrateSource>, RecursiveOptions) {
463
466
// flatten TomlCrates into CrateSources (one TomlCrates may represent several versions of a crate =>
464
467
// multiple Cratesources)
465
468
let mut crate_sources = Vec :: new ( ) ;
466
- tomlcrates . into_iter ( ) . for_each ( |tk| {
469
+ for tk in tomlcrates {
467
470
if let Some ( ref path) = tk. path {
468
471
crate_sources. push ( CrateSource :: Path {
469
472
name : tk. name . clone ( ) ,
@@ -472,13 +475,13 @@ fn read_crates(toml_path: &Path) -> (Vec<CrateSource>, RecursiveOptions) {
472
475
} ) ;
473
476
} else if let Some ( ref versions) = tk. versions {
474
477
// if we have multiple versions, save each one
475
- versions. iter ( ) . for_each ( |ver| {
478
+ for ver in versions. iter ( ) {
476
479
crate_sources. push ( CrateSource :: CratesIo {
477
480
name : tk. name . clone ( ) ,
478
481
version : ver. to_string ( ) ,
479
482
options : tk. options . clone ( ) ,
480
483
} ) ;
481
- } )
484
+ }
482
485
} else if tk. git_url . is_some ( ) && tk. git_hash . is_some ( ) {
483
486
// otherwise, we should have a git source
484
487
crate_sources. push ( CrateSource :: Git {
@@ -496,15 +499,18 @@ fn read_crates(toml_path: &Path) -> (Vec<CrateSource>, RecursiveOptions) {
496
499
|| tk. git_hash . is_some ( ) != tk. git_url . is_some ( )
497
500
{
498
501
eprintln ! ( "tomlkrate: {tk:?}" ) ;
499
- if tk. git_hash . is_some ( ) != tk. git_url . is_some ( ) {
500
- panic ! ( "Error: Encountered TomlCrate with only one of git_hash and git_url!" ) ;
501
- }
502
- if tk. path . is_some ( ) && ( tk. git_hash . is_some ( ) || tk. versions . is_some ( ) ) {
503
- panic ! ( "Error: TomlCrate can only have one of 'git_.*', 'version' or 'path' fields" ) ;
504
- }
502
+ assert_eq ! (
503
+ tk. git_hash. is_some( ) ,
504
+ tk. git_url. is_some( ) ,
505
+ "Error: Encountered TomlCrate with only one of git_hash and git_url!"
506
+ ) ;
507
+ assert ! (
508
+ tk. path. is_none( ) || ( tk. git_hash. is_none( ) && tk. versions. is_none( ) ) ,
509
+ "Error: TomlCrate can only have one of 'git_.*', 'version' or 'path' fields"
510
+ ) ;
505
511
unreachable ! ( "Failed to translate TomlCrate into CrateSource!" ) ;
506
512
}
507
- } ) ;
513
+ }
508
514
// sort the crates
509
515
crate_sources. sort ( ) ;
510
516
@@ -566,6 +572,7 @@ fn lintcheck_needs_rerun(lintcheck_logs_path: &Path, paths: [&Path; 2]) -> bool
566
572
logs_modified < clippy_modified
567
573
}
568
574
575
+ #[ allow( clippy:: too_many_lines) ]
569
576
fn main ( ) {
570
577
// We're being executed as a `RUSTC_WRAPPER` as part of `--recursive`
571
578
if let Ok ( addr) = env:: var ( "LINTCHECK_SERVER" ) {
@@ -671,7 +678,7 @@ fn main() {
671
678
. unwrap ( ) ;
672
679
673
680
let server = config. recursive . then ( || {
674
- let _ = fs:: remove_dir_all ( "target/lintcheck/shared_target_dir/recursive" ) ;
681
+ fs:: remove_dir_all ( "target/lintcheck/shared_target_dir/recursive" ) . unwrap_or_default ( ) ;
675
682
676
683
LintcheckServer :: spawn ( recursive_options)
677
684
} ) ;
@@ -727,7 +734,7 @@ fn main() {
727
734
}
728
735
write ! ( text, "{}" , all_msgs. join( "" ) ) . unwrap ( ) ;
729
736
text. push_str ( "\n \n ### ICEs:\n " ) ;
730
- for ( cratename, msg) in ices. iter ( ) {
737
+ for ( cratename, msg) in & ices {
731
738
let _ = write ! ( text, "{cratename}: '{msg}'" ) ;
732
739
}
733
740
@@ -780,10 +787,10 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
780
787
let mut new_stats_deduped = new_stats;
781
788
782
789
// remove duplicates from both hashmaps
783
- same_in_both_hashmaps . iter ( ) . for_each ( | ( k, v) | {
790
+ for ( k, v) in & same_in_both_hashmaps {
784
791
assert ! ( old_stats_deduped. remove( k) == Some ( * v) ) ;
785
792
assert ! ( new_stats_deduped. remove( k) == Some ( * v) ) ;
786
- } ) ;
793
+ }
787
794
788
795
println ! ( "\n Stats:" ) ;
789
796
@@ -821,19 +828,21 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
821
828
/// This function panics if creating one of the dirs fails.
822
829
fn create_dirs ( krate_download_dir : & Path , extract_dir : & Path ) {
823
830
std:: fs:: create_dir ( "target/lintcheck/" ) . unwrap_or_else ( |err| {
824
- if err. kind ( ) != ErrorKind :: AlreadyExists {
825
- panic ! ( "cannot create lintcheck target dir" ) ;
826
- }
831
+ assert_eq ! (
832
+ err. kind( ) ,
833
+ ErrorKind :: AlreadyExists ,
834
+ "cannot create lintcheck target dir"
835
+ ) ;
827
836
} ) ;
828
837
std:: fs:: create_dir ( krate_download_dir) . unwrap_or_else ( |err| {
829
- if err. kind ( ) != ErrorKind :: AlreadyExists {
830
- panic ! ( "cannot create crate download dir" ) ;
831
- }
838
+ assert_eq ! ( err. kind( ) , ErrorKind :: AlreadyExists , "cannot create crate download dir" ) ;
832
839
} ) ;
833
840
std:: fs:: create_dir ( extract_dir) . unwrap_or_else ( |err| {
834
- if err. kind ( ) != ErrorKind :: AlreadyExists {
835
- panic ! ( "cannot create crate extraction dir" ) ;
836
- }
841
+ assert_eq ! (
842
+ err. kind( ) ,
843
+ ErrorKind :: AlreadyExists ,
844
+ "cannot create crate extraction dir"
845
+ ) ;
837
846
} ) ;
838
847
}
839
848
0 commit comments