@@ -116,12 +116,13 @@ impl ClippyWarning {
116116
117117 let span = diag. spans . into_iter ( ) . find ( |span| span. is_primary ) ?;
118118
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 ! (
122123 "target/lintcheck/sources/{}-{}/{}" ,
123124 crate_name, crate_version, span. file_name
124- ) ,
125+ )
125126 } ;
126127
127128 Some ( Self {
@@ -154,6 +155,7 @@ impl ClippyWarning {
154155 }
155156}
156157
158+ #[ allow( clippy:: result_large_err) ]
157159fn get ( path : & str ) -> Result < ureq:: Response , ureq:: Error > {
158160 const MAX_RETRIES : u8 = 4 ;
159161 let mut retries = 0 ;
@@ -165,7 +167,7 @@ fn get(path: &str) -> Result<ureq::Response, ureq::Error> {
165167 Err ( e) => return Err ( e) ,
166168 }
167169 eprintln ! ( "retrying in {retries} seconds..." ) ;
168- thread:: sleep ( Duration :: from_secs ( retries as u64 ) ) ;
170+ thread:: sleep ( Duration :: from_secs ( u64:: from ( retries ) ) ) ;
169171 retries += 1 ;
170172 }
171173}
@@ -232,7 +234,7 @@ impl CrateSource {
232234 . expect ( "Failed to clone git repo!" )
233235 . success ( )
234236 {
235- eprintln ! ( "Failed to clone {url} into {}" , repo_path. display( ) )
237+ eprintln ! ( "Failed to clone {url} into {}" , repo_path. display( ) ) ;
236238 }
237239 }
238240 // check out the commit/branch/whatever
@@ -245,7 +247,7 @@ impl CrateSource {
245247 . expect ( "Failed to check out commit" )
246248 . success ( )
247249 {
248- eprintln ! ( "Failed to checkout {commit} of repo at {}" , repo_path. display( ) )
250+ eprintln ! ( "Failed to checkout {commit} of repo at {}" , repo_path. display( ) ) ;
249251 }
250252
251253 Crate {
@@ -256,6 +258,12 @@ impl CrateSource {
256258 }
257259 } ,
258260 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+
259267 // copy path into the dest_crate_root but skip directories that contain a CACHEDIR.TAG file.
260268 // The target/ directory contains a CACHEDIR.TAG file so it is the most commonly skipped directory
261269 // as a result of this filter.
@@ -267,12 +275,6 @@ impl CrateSource {
267275
268276 println ! ( "Copying {path:?} to {dest_crate_root:?}" ) ;
269277
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-
276278 for entry in WalkDir :: new ( path) . into_iter ( ) . filter_entry ( |e| !is_cache_dir ( e) ) {
277279 let entry = entry. unwrap ( ) ;
278280 let entry_path = entry. path ( ) ;
@@ -301,6 +303,7 @@ impl CrateSource {
301303impl Crate {
302304 /// Run `cargo clippy` on the `Crate` and collect and return all the lint warnings that clippy
303305 /// issued
306+ #[ allow( clippy:: too_many_arguments) ]
304307 fn run_clippy_lints (
305308 & self ,
306309 cargo_clippy_path : & Path ,
@@ -345,14 +348,14 @@ impl Crate {
345348 clippy_args. push ( opt) ;
346349 }
347350 } else {
348- clippy_args. extend ( [ "-Wclippy::pedantic" , "-Wclippy::cargo" ] )
351+ clippy_args. extend ( [ "-Wclippy::pedantic" , "-Wclippy::cargo" ] ) ;
349352 }
350353
351354 if lint_filter. is_empty ( ) {
352355 clippy_args. push ( "--cap-lints=warn" ) ;
353356 } else {
354357 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) ) ;
356359 }
357360
358361 if let Some ( server) = server {
@@ -463,7 +466,7 @@ fn read_crates(toml_path: &Path) -> (Vec<CrateSource>, RecursiveOptions) {
463466 // flatten TomlCrates into CrateSources (one TomlCrates may represent several versions of a crate =>
464467 // multiple Cratesources)
465468 let mut crate_sources = Vec :: new ( ) ;
466- tomlcrates . into_iter ( ) . for_each ( |tk| {
469+ for tk in tomlcrates {
467470 if let Some ( ref path) = tk. path {
468471 crate_sources. push ( CrateSource :: Path {
469472 name : tk. name . clone ( ) ,
@@ -472,13 +475,13 @@ fn read_crates(toml_path: &Path) -> (Vec<CrateSource>, RecursiveOptions) {
472475 } ) ;
473476 } else if let Some ( ref versions) = tk. versions {
474477 // if we have multiple versions, save each one
475- versions. iter ( ) . for_each ( |ver| {
478+ for ver in versions. iter ( ) {
476479 crate_sources. push ( CrateSource :: CratesIo {
477480 name : tk. name . clone ( ) ,
478481 version : ver. to_string ( ) ,
479482 options : tk. options . clone ( ) ,
480483 } ) ;
481- } )
484+ }
482485 } else if tk. git_url . is_some ( ) && tk. git_hash . is_some ( ) {
483486 // otherwise, we should have a git source
484487 crate_sources. push ( CrateSource :: Git {
@@ -496,15 +499,18 @@ fn read_crates(toml_path: &Path) -> (Vec<CrateSource>, RecursiveOptions) {
496499 || tk. git_hash . is_some ( ) != tk. git_url . is_some ( )
497500 {
498501 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+ ) ;
505511 unreachable ! ( "Failed to translate TomlCrate into CrateSource!" ) ;
506512 }
507- } ) ;
513+ }
508514 // sort the crates
509515 crate_sources. sort ( ) ;
510516
@@ -566,6 +572,7 @@ fn lintcheck_needs_rerun(lintcheck_logs_path: &Path, paths: [&Path; 2]) -> bool
566572 logs_modified < clippy_modified
567573}
568574
575+ #[ allow( clippy:: too_many_lines) ]
569576fn main ( ) {
570577 // We're being executed as a `RUSTC_WRAPPER` as part of `--recursive`
571578 if let Ok ( addr) = env:: var ( "LINTCHECK_SERVER" ) {
@@ -671,7 +678,7 @@ fn main() {
671678 . unwrap ( ) ;
672679
673680 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 ( ) ;
675682
676683 LintcheckServer :: spawn ( recursive_options)
677684 } ) ;
@@ -727,7 +734,7 @@ fn main() {
727734 }
728735 write ! ( text, "{}" , all_msgs. join( "" ) ) . unwrap ( ) ;
729736 text. push_str ( "\n \n ### ICEs:\n " ) ;
730- for ( cratename, msg) in ices. iter ( ) {
737+ for ( cratename, msg) in & ices {
731738 let _ = write ! ( text, "{cratename}: '{msg}'" ) ;
732739 }
733740
@@ -780,10 +787,10 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
780787 let mut new_stats_deduped = new_stats;
781788
782789 // remove duplicates from both hashmaps
783- same_in_both_hashmaps . iter ( ) . for_each ( | ( k, v) | {
790+ for ( k, v) in & same_in_both_hashmaps {
784791 assert ! ( old_stats_deduped. remove( k) == Some ( * v) ) ;
785792 assert ! ( new_stats_deduped. remove( k) == Some ( * v) ) ;
786- } ) ;
793+ }
787794
788795 println ! ( "\n Stats:" ) ;
789796
@@ -821,19 +828,21 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
821828/// This function panics if creating one of the dirs fails.
822829fn create_dirs ( krate_download_dir : & Path , extract_dir : & Path ) {
823830 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+ ) ;
827836 } ) ;
828837 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" ) ;
832839 } ) ;
833840 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+ ) ;
837846 } ) ;
838847}
839848
0 commit comments