@@ -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 {
@@ -144,28 +145,29 @@ impl ClippyWarning {
144145 }
145146
146147 let mut output = String :: from ( "| " ) ;
147- let _ = write ! ( output, "[`{}`]({}#L{})" , file_with_pos , file , self . line) ;
148+ let _ = write ! ( output, "[`{file_with_pos }`]({file }#L{})" , self . line) ;
148149 let _ = write ! ( output, r#" | `{:<50}` | "{}" |"# , self . lint_type, self . message) ;
149150 output. push ( '\n' ) ;
150151 output
151152 } else {
152- format ! ( "{} {} \" {}\" \n " , file_with_pos , self . lint_type, self . message)
153+ format ! ( "{file_with_pos } {} \" {}\" \n " , self . lint_type, self . message)
153154 }
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 ;
160162 loop {
161163 match ureq:: get ( path) . call ( ) {
162164 Ok ( res) => return Ok ( res) ,
163165 Err ( e) if retries >= MAX_RETRIES => return Err ( e) ,
164- Err ( ureq:: Error :: Transport ( e) ) => eprintln ! ( "Error: {}" , e ) ,
166+ Err ( ureq:: Error :: Transport ( e) ) => eprintln ! ( "Error: {e}" ) ,
165167 Err ( e) => return Err ( e) ,
166168 }
167- eprintln ! ( "retrying in {} seconds..." , retries ) ;
168- thread:: sleep ( Duration :: from_secs ( retries as u64 ) ) ;
169+ eprintln ! ( "retrying in {retries } seconds..." ) ;
170+ thread:: sleep ( Duration :: from_secs ( u64:: from ( retries ) ) ) ;
169171 retries += 1 ;
170172 }
171173}
@@ -181,11 +183,11 @@ impl CrateSource {
181183 let krate_download_dir = PathBuf :: from ( LINTCHECK_DOWNLOADS ) ;
182184
183185 // url to download the crate from crates.io
184- let url = format ! ( "https://crates.io/api/v1/crates/{}/{}/download" , name , version ) ;
185- println ! ( "Downloading and extracting {} {} from {}" , name , version , url ) ;
186+ let url = format ! ( "https://crates.io/api/v1/crates/{name }/{version }/download" ) ;
187+ println ! ( "Downloading and extracting {name } {version } from {url}" ) ;
186188 create_dirs ( & krate_download_dir, & extract_dir) ;
187189
188- let krate_file_path = krate_download_dir. join ( format ! ( "{}-{}.crate.tar.gz" , name , version ) ) ;
190+ let krate_file_path = krate_download_dir. join ( format ! ( "{name }-{version }.crate.tar.gz" ) ) ;
189191 // don't download/extract if we already have done so
190192 if !krate_file_path. is_file ( ) {
191193 // create a file path to download and write the crate data into
@@ -205,7 +207,7 @@ impl CrateSource {
205207 Crate {
206208 version : version. clone ( ) ,
207209 name : name. clone ( ) ,
208- path : extract_dir. join ( format ! ( "{}-{}/" , name , version ) ) ,
210+ path : extract_dir. join ( format ! ( "{name }-{version }/" ) ) ,
209211 options : options. clone ( ) ,
210212 }
211213 } ,
@@ -218,12 +220,12 @@ impl CrateSource {
218220 let repo_path = {
219221 let mut repo_path = PathBuf :: from ( LINTCHECK_SOURCES ) ;
220222 // add a -git suffix in case we have the same crate from crates.io and a git repo
221- repo_path. push ( format ! ( "{}-git" , name ) ) ;
223+ repo_path. push ( format ! ( "{name }-git" ) ) ;
222224 repo_path
223225 } ;
224226 // clone the repo if we have not done so
225227 if !repo_path. is_dir ( ) {
226- println ! ( "Cloning {} and checking out {}" , url , commit ) ;
228+ println ! ( "Cloning {url } and checking out {commit}" ) ;
227229 if !Command :: new ( "git" )
228230 . arg ( "clone" )
229231 . arg ( url)
@@ -232,7 +234,7 @@ impl CrateSource {
232234 . expect ( "Failed to clone git repo!" )
233235 . success ( )
234236 {
235- eprintln ! ( "Failed to clone {} into {}" , url , 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 {} of repo at {}" , commit , repo_path. display( ) )
250+ eprintln ! ( "Failed to checkout {commit } of repo at {}" , repo_path. display( ) ) ;
249251 }
250252
251253 Crate {
@@ -256,22 +258,22 @@ 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.
262270 let dest_crate_root = PathBuf :: from ( LINTCHECK_SOURCES ) . join ( name) ;
263271 if dest_crate_root. exists ( ) {
264- println ! ( "Deleting existing directory at {:?}" , dest_crate_root ) ;
272+ println ! ( "Deleting existing directory at {dest_crate_root :?}" ) ;
265273 std:: fs:: remove_dir_all ( & dest_crate_root) . unwrap ( ) ;
266274 }
267275
268- println ! ( "Copying {:?} to {:?}" , path, dest_crate_root) ;
269-
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- }
276+ println ! ( "Copying {path:?} to {dest_crate_root:?}" ) ;
275277
276278 for entry in WalkDir :: new ( path) . into_iter ( ) . filter_entry ( |e| !is_cache_dir ( e) ) {
277279 let entry = entry. unwrap ( ) ;
@@ -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 {
@@ -389,10 +392,7 @@ impl Crate {
389392
390393 let all_output = Command :: new ( & cargo_clippy_path)
391394 // use the looping index to create individual target dirs
392- . env (
393- "CARGO_TARGET_DIR" ,
394- shared_target_dir. join ( format ! ( "_{:?}" , thread_index) ) ,
395- )
395+ . env ( "CARGO_TARGET_DIR" , shared_target_dir. join ( format ! ( "_{thread_index:?}" ) ) )
396396 . args ( & cargo_clippy_args)
397397 . current_dir ( & self . path )
398398 . output ( )
@@ -422,8 +422,8 @@ impl Crate {
422422 {
423423 let subcrate = & stderr[ 63 ..] ;
424424 println ! (
425- "ERROR: failed to apply some suggetion to {} / to (sub)crate {}" ,
426- self . name, subcrate
425+ "ERROR: failed to apply some suggetion to {} / to (sub)crate {subcrate }" ,
426+ self . name
427427 ) ;
428428 }
429429 // fast path, we don't need the warnings anyway
@@ -459,14 +459,14 @@ fn read_crates(toml_path: &Path) -> (Vec<CrateSource>, RecursiveOptions) {
459459 let toml_content: String =
460460 std:: fs:: read_to_string ( toml_path) . unwrap_or_else ( |_| panic ! ( "Failed to read {}" , toml_path. display( ) ) ) ;
461461 let crate_list: SourceList =
462- toml:: from_str ( & toml_content) . unwrap_or_else ( |e| panic ! ( "Failed to parse {}: \n {}" , toml_path. display( ) , e ) ) ;
462+ toml:: from_str ( & toml_content) . unwrap_or_else ( |e| panic ! ( "Failed to parse {}: \n {e }" , toml_path. display( ) ) ) ;
463463 // parse the hashmap of the toml file into a list of crates
464464 let tomlcrates: Vec < TomlCrate > = crate_list. crates . into_values ( ) . collect ( ) ;
465465
466466 // flatten TomlCrates into CrateSources (one TomlCrates may represent several versions of a crate =>
467467 // multiple Cratesources)
468468 let mut crate_sources = Vec :: new ( ) ;
469- tomlcrates . into_iter ( ) . for_each ( |tk| {
469+ for tk in tomlcrates {
470470 if let Some ( ref path) = tk. path {
471471 crate_sources. push ( CrateSource :: Path {
472472 name : tk. name . clone ( ) ,
@@ -475,13 +475,13 @@ fn read_crates(toml_path: &Path) -> (Vec<CrateSource>, RecursiveOptions) {
475475 } ) ;
476476 } else if let Some ( ref versions) = tk. versions {
477477 // if we have multiple versions, save each one
478- versions. iter ( ) . for_each ( |ver| {
478+ for ver in versions. iter ( ) {
479479 crate_sources. push ( CrateSource :: CratesIo {
480480 name : tk. name . clone ( ) ,
481481 version : ver. to_string ( ) ,
482482 options : tk. options . clone ( ) ,
483483 } ) ;
484- } )
484+ }
485485 } else if tk. git_url . is_some ( ) && tk. git_hash . is_some ( ) {
486486 // otherwise, we should have a git source
487487 crate_sources. push ( CrateSource :: Git {
@@ -498,16 +498,19 @@ fn read_crates(toml_path: &Path) -> (Vec<CrateSource>, RecursiveOptions) {
498498 if tk. versions . is_some ( ) && ( tk. git_url . is_some ( ) || tk. git_hash . is_some ( ) )
499499 || tk. git_hash . is_some ( ) != tk. git_url . is_some ( )
500500 {
501- eprintln ! ( "tomlkrate: {:?}" , tk) ;
502- if tk. git_hash . is_some ( ) != tk. git_url . is_some ( ) {
503- panic ! ( "Error: Encountered TomlCrate with only one of git_hash and git_url!" ) ;
504- }
505- if tk. path . is_some ( ) && ( tk. git_hash . is_some ( ) || tk. versions . is_some ( ) ) {
506- panic ! ( "Error: TomlCrate can only have one of 'git_.*', 'version' or 'path' fields" ) ;
507- }
501+ eprintln ! ( "tomlkrate: {tk:?}" ) ;
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+ ) ;
508511 unreachable ! ( "Failed to translate TomlCrate into CrateSource!" ) ;
509512 }
510- } ) ;
513+ }
511514 // sort the crates
512515 crate_sources. sort ( ) ;
513516
@@ -526,13 +529,13 @@ fn gather_stats(clippy_warnings: &[ClippyWarning]) -> (String, HashMap<&String,
526529 let mut stats: Vec < ( & & String , & usize ) > = counter. iter ( ) . map ( |( lint, count) | ( lint, count) ) . collect ( ) ;
527530 // sort by "000{count} {clippy::lintname}"
528531 // to not have a lint with 200 and 2 warnings take the same spot
529- stats. sort_by_key ( |( lint, count) | format ! ( "{:0>4}, {}" , count , lint ) ) ;
532+ stats. sort_by_key ( |( lint, count) | format ! ( "{count :0>4}, {lint}" ) ) ;
530533
531534 let mut header = String :: from ( "| lint | count |\n " ) ;
532535 header. push_str ( "| -------------------------------------------------- | ----- |\n " ) ;
533536 let stats_string = stats
534537 . iter ( )
535- . map ( |( lint, count) | format ! ( "| {:<50} | {:>4} |\n " , lint , count ) )
538+ . map ( |( lint, count) | format ! ( "| {lint :<50} | {count :>4} |\n " ) )
536539 . fold ( header, |mut table, line| {
537540 table. push_str ( & line) ;
538541 table
@@ -569,6 +572,7 @@ fn lintcheck_needs_rerun(lintcheck_logs_path: &Path, paths: [&Path; 2]) -> bool
569572 logs_modified < clippy_modified
570573}
571574
575+ #[ allow( clippy:: too_many_lines) ]
572576fn main ( ) {
573577 // We're being executed as a `RUSTC_WRAPPER` as part of `--recursive`
574578 if let Ok ( addr) = env:: var ( "LINTCHECK_SERVER" ) {
@@ -674,7 +678,7 @@ fn main() {
674678 . unwrap ( ) ;
675679
676680 let server = config. recursive . then ( || {
677- 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 ( ) ;
678682
679683 LintcheckServer :: spawn ( recursive_options)
680684 } ) ;
@@ -730,8 +734,8 @@ fn main() {
730734 }
731735 write ! ( text, "{}" , all_msgs. join( "" ) ) . unwrap ( ) ;
732736 text. push_str ( "\n \n ### ICEs:\n " ) ;
733- for ( cratename, msg) in ices. iter ( ) {
734- let _ = write ! ( text, "{}: '{}'" , cratename , msg ) ;
737+ for ( cratename, msg) in & ices {
738+ let _ = write ! ( text, "{cratename }: '{msg }'" ) ;
735739 }
736740
737741 println ! ( "Writing logs to {}" , config. lintcheck_results_path. display( ) ) ;
@@ -783,10 +787,10 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
783787 let mut new_stats_deduped = new_stats;
784788
785789 // remove duplicates from both hashmaps
786- same_in_both_hashmaps . iter ( ) . for_each ( | ( k, v) | {
790+ for ( k, v) in & same_in_both_hashmaps {
787791 assert ! ( old_stats_deduped. remove( k) == Some ( * v) ) ;
788792 assert ! ( new_stats_deduped. remove( k) == Some ( * v) ) ;
789- } ) ;
793+ }
790794
791795 println ! ( "\n Stats:" ) ;
792796
@@ -795,7 +799,7 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
795799 . iter ( )
796800 . filter ( |( new_key, _) | old_stats_deduped. get :: < str > ( new_key) . is_none ( ) )
797801 . for_each ( |( new_key, new_value) | {
798- println ! ( "{} 0 => {}" , new_key , new_value ) ;
802+ println ! ( "{new_key } 0 => {new_value}" ) ;
799803 } ) ;
800804
801805 // list all changed counts (key is in both maps but value differs)
@@ -804,7 +808,7 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
804808 . filter ( |( new_key, _new_val) | old_stats_deduped. get :: < str > ( new_key) . is_some ( ) )
805809 . for_each ( |( new_key, new_val) | {
806810 let old_val = old_stats_deduped. get :: < str > ( new_key) . unwrap ( ) ;
807- println ! ( "{} {} => {}" , new_key , old_val , new_val ) ;
811+ println ! ( "{new_key } {old_val } => {new_val}" ) ;
808812 } ) ;
809813
810814 // list all gone counts (key is in old status but not in new stats)
@@ -813,7 +817,7 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
813817 . filter ( |( old_key, _) | new_stats_deduped. get :: < & String > ( old_key) . is_none ( ) )
814818 . filter ( |( old_key, _) | lint_filter. is_empty ( ) || lint_filter. contains ( old_key) )
815819 . for_each ( |( old_key, old_value) | {
816- println ! ( "{} {} => 0" , old_key , old_value ) ;
820+ println ! ( "{old_key } {old_value } => 0" ) ;
817821 } ) ;
818822}
819823
@@ -824,19 +828,21 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
824828/// This function panics if creating one of the dirs fails.
825829fn create_dirs ( krate_download_dir : & Path , extract_dir : & Path ) {
826830 std:: fs:: create_dir ( "target/lintcheck/" ) . unwrap_or_else ( |err| {
827- if err. kind ( ) != ErrorKind :: AlreadyExists {
828- panic ! ( "cannot create lintcheck target dir" ) ;
829- }
831+ assert_eq ! (
832+ err. kind( ) ,
833+ ErrorKind :: AlreadyExists ,
834+ "cannot create lintcheck target dir"
835+ ) ;
830836 } ) ;
831837 std:: fs:: create_dir ( krate_download_dir) . unwrap_or_else ( |err| {
832- if err. kind ( ) != ErrorKind :: AlreadyExists {
833- panic ! ( "cannot create crate download dir" ) ;
834- }
838+ assert_eq ! ( err. kind( ) , ErrorKind :: AlreadyExists , "cannot create crate download dir" ) ;
835839 } ) ;
836840 std:: fs:: create_dir ( extract_dir) . unwrap_or_else ( |err| {
837- if err. kind ( ) != ErrorKind :: AlreadyExists {
838- panic ! ( "cannot create crate extraction dir" ) ;
839- }
841+ assert_eq ! (
842+ err. kind( ) ,
843+ ErrorKind :: AlreadyExists ,
844+ "cannot create crate extraction dir"
845+ ) ;
840846 } ) ;
841847}
842848
0 commit comments