@@ -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 {
@@ -144,28 +145,29 @@ impl ClippyWarning {
144
145
}
145
146
146
147
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) ;
148
149
let _ = write ! ( output, r#" | `{:<50}` | "{}" |"# , self . lint_type, self . message) ;
149
150
output. push ( '\n' ) ;
150
151
output
151
152
} else {
152
- format ! ( "{} {} \" {}\" \n " , file_with_pos , self . lint_type, self . message)
153
+ format ! ( "{file_with_pos } {} \" {}\" \n " , self . lint_type, self . message)
153
154
}
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 ;
160
162
loop {
161
163
match ureq:: get ( path) . call ( ) {
162
164
Ok ( res) => return Ok ( res) ,
163
165
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}" ) ,
165
167
Err ( e) => return Err ( e) ,
166
168
}
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 ) ) ) ;
169
171
retries += 1 ;
170
172
}
171
173
}
@@ -181,11 +183,11 @@ impl CrateSource {
181
183
let krate_download_dir = PathBuf :: from ( LINTCHECK_DOWNLOADS ) ;
182
184
183
185
// 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}" ) ;
186
188
create_dirs ( & krate_download_dir, & extract_dir) ;
187
189
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" ) ) ;
189
191
// don't download/extract if we already have done so
190
192
if !krate_file_path. is_file ( ) {
191
193
// create a file path to download and write the crate data into
@@ -205,7 +207,7 @@ impl CrateSource {
205
207
Crate {
206
208
version : version. clone ( ) ,
207
209
name : name. clone ( ) ,
208
- path : extract_dir. join ( format ! ( "{}-{}/" , name , version ) ) ,
210
+ path : extract_dir. join ( format ! ( "{name }-{version }/" ) ) ,
209
211
options : options. clone ( ) ,
210
212
}
211
213
} ,
@@ -218,12 +220,12 @@ impl CrateSource {
218
220
let repo_path = {
219
221
let mut repo_path = PathBuf :: from ( LINTCHECK_SOURCES ) ;
220
222
// 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" ) ) ;
222
224
repo_path
223
225
} ;
224
226
// clone the repo if we have not done so
225
227
if !repo_path. is_dir ( ) {
226
- println ! ( "Cloning {} and checking out {}" , url , commit ) ;
228
+ println ! ( "Cloning {url } and checking out {commit}" ) ;
227
229
if !Command :: new ( "git" )
228
230
. arg ( "clone" )
229
231
. arg ( url)
@@ -232,7 +234,7 @@ impl CrateSource {
232
234
. expect ( "Failed to clone git repo!" )
233
235
. success ( )
234
236
{
235
- eprintln ! ( "Failed to clone {} into {}" , url , 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 {} of repo at {}" , commit , repo_path. display( ) )
250
+ eprintln ! ( "Failed to checkout {commit } of repo at {}" , repo_path. display( ) ) ;
249
251
}
250
252
251
253
Crate {
@@ -256,22 +258,22 @@ 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.
262
270
let dest_crate_root = PathBuf :: from ( LINTCHECK_SOURCES ) . join ( name) ;
263
271
if dest_crate_root. exists ( ) {
264
- println ! ( "Deleting existing directory at {:?}" , dest_crate_root ) ;
272
+ println ! ( "Deleting existing directory at {dest_crate_root :?}" ) ;
265
273
std:: fs:: remove_dir_all ( & dest_crate_root) . unwrap ( ) ;
266
274
}
267
275
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:?}" ) ;
275
277
276
278
for entry in WalkDir :: new ( path) . into_iter ( ) . filter_entry ( |e| !is_cache_dir ( e) ) {
277
279
let entry = entry. unwrap ( ) ;
@@ -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 {
@@ -389,10 +392,7 @@ impl Crate {
389
392
390
393
let all_output = Command :: new ( & cargo_clippy_path)
391
394
// 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:?}" ) ) )
396
396
. args ( & cargo_clippy_args)
397
397
. current_dir ( & self . path )
398
398
. output ( )
@@ -422,8 +422,8 @@ impl Crate {
422
422
{
423
423
let subcrate = & stderr[ 63 ..] ;
424
424
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
427
427
) ;
428
428
}
429
429
// fast path, we don't need the warnings anyway
@@ -459,14 +459,14 @@ fn read_crates(toml_path: &Path) -> (Vec<CrateSource>, RecursiveOptions) {
459
459
let toml_content: String =
460
460
std:: fs:: read_to_string ( toml_path) . unwrap_or_else ( |_| panic ! ( "Failed to read {}" , toml_path. display( ) ) ) ;
461
461
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( ) ) ) ;
463
463
// parse the hashmap of the toml file into a list of crates
464
464
let tomlcrates: Vec < TomlCrate > = crate_list. crates . into_values ( ) . collect ( ) ;
465
465
466
466
// flatten TomlCrates into CrateSources (one TomlCrates may represent several versions of a crate =>
467
467
// multiple Cratesources)
468
468
let mut crate_sources = Vec :: new ( ) ;
469
- tomlcrates . into_iter ( ) . for_each ( |tk| {
469
+ for tk in tomlcrates {
470
470
if let Some ( ref path) = tk. path {
471
471
crate_sources. push ( CrateSource :: Path {
472
472
name : tk. name . clone ( ) ,
@@ -475,13 +475,13 @@ fn read_crates(toml_path: &Path) -> (Vec<CrateSource>, RecursiveOptions) {
475
475
} ) ;
476
476
} else if let Some ( ref versions) = tk. versions {
477
477
// if we have multiple versions, save each one
478
- versions. iter ( ) . for_each ( |ver| {
478
+ for ver in versions. iter ( ) {
479
479
crate_sources. push ( CrateSource :: CratesIo {
480
480
name : tk. name . clone ( ) ,
481
481
version : ver. to_string ( ) ,
482
482
options : tk. options . clone ( ) ,
483
483
} ) ;
484
- } )
484
+ }
485
485
} else if tk. git_url . is_some ( ) && tk. git_hash . is_some ( ) {
486
486
// otherwise, we should have a git source
487
487
crate_sources. push ( CrateSource :: Git {
@@ -498,16 +498,19 @@ fn read_crates(toml_path: &Path) -> (Vec<CrateSource>, RecursiveOptions) {
498
498
if tk. versions . is_some ( ) && ( tk. git_url . is_some ( ) || tk. git_hash . is_some ( ) )
499
499
|| tk. git_hash . is_some ( ) != tk. git_url . is_some ( )
500
500
{
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
+ ) ;
508
511
unreachable ! ( "Failed to translate TomlCrate into CrateSource!" ) ;
509
512
}
510
- } ) ;
513
+ }
511
514
// sort the crates
512
515
crate_sources. sort ( ) ;
513
516
@@ -526,13 +529,13 @@ fn gather_stats(clippy_warnings: &[ClippyWarning]) -> (String, HashMap<&String,
526
529
let mut stats: Vec < ( & & String , & usize ) > = counter. iter ( ) . map ( |( lint, count) | ( lint, count) ) . collect ( ) ;
527
530
// sort by "000{count} {clippy::lintname}"
528
531
// 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}" ) ) ;
530
533
531
534
let mut header = String :: from ( "| lint | count |\n " ) ;
532
535
header. push_str ( "| -------------------------------------------------- | ----- |\n " ) ;
533
536
let stats_string = stats
534
537
. iter ( )
535
- . map ( |( lint, count) | format ! ( "| {:<50} | {:>4} |\n " , lint , count ) )
538
+ . map ( |( lint, count) | format ! ( "| {lint :<50} | {count :>4} |\n " ) )
536
539
. fold ( header, |mut table, line| {
537
540
table. push_str ( & line) ;
538
541
table
@@ -569,6 +572,7 @@ fn lintcheck_needs_rerun(lintcheck_logs_path: &Path, paths: [&Path; 2]) -> bool
569
572
logs_modified < clippy_modified
570
573
}
571
574
575
+ #[ allow( clippy:: too_many_lines) ]
572
576
fn main ( ) {
573
577
// We're being executed as a `RUSTC_WRAPPER` as part of `--recursive`
574
578
if let Ok ( addr) = env:: var ( "LINTCHECK_SERVER" ) {
@@ -674,7 +678,7 @@ fn main() {
674
678
. unwrap ( ) ;
675
679
676
680
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 ( ) ;
678
682
679
683
LintcheckServer :: spawn ( recursive_options)
680
684
} ) ;
@@ -730,8 +734,8 @@ fn main() {
730
734
}
731
735
write ! ( text, "{}" , all_msgs. join( "" ) ) . unwrap ( ) ;
732
736
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 }'" ) ;
735
739
}
736
740
737
741
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
783
787
let mut new_stats_deduped = new_stats;
784
788
785
789
// remove duplicates from both hashmaps
786
- same_in_both_hashmaps . iter ( ) . for_each ( | ( k, v) | {
790
+ for ( k, v) in & same_in_both_hashmaps {
787
791
assert ! ( old_stats_deduped. remove( k) == Some ( * v) ) ;
788
792
assert ! ( new_stats_deduped. remove( k) == Some ( * v) ) ;
789
- } ) ;
793
+ }
790
794
791
795
println ! ( "\n Stats:" ) ;
792
796
@@ -795,7 +799,7 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
795
799
. iter ( )
796
800
. filter ( |( new_key, _) | old_stats_deduped. get :: < str > ( new_key) . is_none ( ) )
797
801
. for_each ( |( new_key, new_value) | {
798
- println ! ( "{} 0 => {}" , new_key , new_value ) ;
802
+ println ! ( "{new_key } 0 => {new_value}" ) ;
799
803
} ) ;
800
804
801
805
// 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
804
808
. filter ( |( new_key, _new_val) | old_stats_deduped. get :: < str > ( new_key) . is_some ( ) )
805
809
. for_each ( |( new_key, new_val) | {
806
810
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}" ) ;
808
812
} ) ;
809
813
810
814
// 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
813
817
. filter ( |( old_key, _) | new_stats_deduped. get :: < & String > ( old_key) . is_none ( ) )
814
818
. filter ( |( old_key, _) | lint_filter. is_empty ( ) || lint_filter. contains ( old_key) )
815
819
. for_each ( |( old_key, old_value) | {
816
- println ! ( "{} {} => 0" , old_key , old_value ) ;
820
+ println ! ( "{old_key } {old_value } => 0" ) ;
817
821
} ) ;
818
822
}
819
823
@@ -824,19 +828,21 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
824
828
/// This function panics if creating one of the dirs fails.
825
829
fn create_dirs ( krate_download_dir : & Path , extract_dir : & Path ) {
826
830
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
+ ) ;
830
836
} ) ;
831
837
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" ) ;
835
839
} ) ;
836
840
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
+ ) ;
840
846
} ) ;
841
847
}
842
848
0 commit comments