5
5
// positives.
6
6
7
7
#![ cfg( feature = "lintcheck" ) ]
8
- #![ allow( clippy:: filter_map) ]
8
+ #![ allow( clippy:: filter_map, clippy:: collapsible_else_if) ]
9
+ #![ allow( clippy:: blocks_in_if_conditions) ] // FP on `if x.iter().any(|x| ...)`
9
10
10
11
use crate :: clippy_project_root;
11
12
12
13
use std:: collections:: HashMap ;
13
14
use std:: process:: Command ;
14
15
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
15
- use std:: { env, fmt, fs:: write, path:: PathBuf } ;
16
+ use std:: {
17
+ env, fmt,
18
+ fs:: write,
19
+ path:: { Path , PathBuf } ,
20
+ } ;
16
21
17
22
use clap:: ArgMatches ;
18
23
use rayon:: prelude:: * ;
@@ -196,11 +201,9 @@ impl CrateSource {
196
201
if !crate_root. exists ( ) {
197
202
println ! ( "Copying {} to {}" , path. display( ) , copy_dest. display( ) ) ;
198
203
199
- dir:: copy ( path, & copy_dest, & dir:: CopyOptions :: new ( ) ) . expect ( & format ! (
200
- "Failed to copy from {}, to {}" ,
201
- path. display( ) ,
202
- crate_root. display( )
203
- ) ) ;
204
+ dir:: copy ( path, & copy_dest, & dir:: CopyOptions :: new ( ) ) . unwrap_or_else ( |_| {
205
+ panic ! ( "Failed to copy from {}, to {}" , path. display( ) , crate_root. display( ) )
206
+ } ) ;
204
207
} else {
205
208
println ! (
206
209
"Not copying {} to {}, destination already exists" ,
@@ -225,7 +228,7 @@ impl Crate {
225
228
/// issued
226
229
fn run_clippy_lints (
227
230
& self ,
228
- cargo_clippy_path : & PathBuf ,
231
+ cargo_clippy_path : & Path ,
229
232
target_dir_index : & AtomicUsize ,
230
233
thread_limit : usize ,
231
234
total_crates_to_lint : usize ,
@@ -308,13 +311,13 @@ impl LintcheckConfig {
308
311
// first, check if we got anything passed via the LINTCHECK_TOML env var,
309
312
// if not, ask clap if we got any value for --crates-toml <foo>
310
313
// if not, use the default "clippy_dev/lintcheck_crates.toml"
311
- let sources_toml = env:: var ( "LINTCHECK_TOML" ) . unwrap_or (
314
+ let sources_toml = env:: var ( "LINTCHECK_TOML" ) . unwrap_or_else ( |_| {
312
315
clap_config
313
316
. value_of ( "crates-toml" )
314
317
. clone ( )
315
318
. unwrap_or ( "clippy_dev/lintcheck_crates.toml" )
316
- . to_string ( ) ,
317
- ) ;
319
+ . to_string ( )
320
+ } ) ;
318
321
319
322
let sources_toml_path = PathBuf :: from ( sources_toml) ;
320
323
@@ -330,7 +333,7 @@ impl LintcheckConfig {
330
333
Some ( threads) => {
331
334
let threads: usize = threads
332
335
. parse ( )
333
- . expect ( & format ! ( "Failed to parse '{}' to a digit" , threads) ) ;
336
+ . unwrap_or_else ( |_| panic ! ( "Failed to parse '{}' to a digit" , threads) ) ;
334
337
if threads == 0 {
335
338
// automatic choice
336
339
// Rayon seems to return thread count so half that for core count
@@ -387,7 +390,7 @@ fn build_clippy() {
387
390
}
388
391
389
392
/// Read a `toml` file and return a list of `CrateSources` that we want to check with clippy
390
- fn read_crates ( toml_path : & PathBuf ) -> Vec < CrateSource > {
393
+ fn read_crates ( toml_path : & Path ) -> Vec < CrateSource > {
391
394
let toml_content: String =
392
395
std:: fs:: read_to_string ( & toml_path) . unwrap_or_else ( |_| panic ! ( "Failed to read {}" , toml_path. display( ) ) ) ;
393
396
let crate_list: SourceList =
@@ -499,7 +502,7 @@ fn gather_stats(clippy_warnings: &[ClippyWarning]) -> (String, HashMap<&String,
499
502
500
503
/// check if the latest modification of the logfile is older than the modification date of the
501
504
/// clippy binary, if this is true, we should clean the lintchec shared target directory and recheck
502
- fn lintcheck_needs_rerun ( lintcheck_logs_path : & PathBuf ) -> bool {
505
+ fn lintcheck_needs_rerun ( lintcheck_logs_path : & Path ) -> bool {
503
506
let clippy_modified: std:: time:: SystemTime = {
504
507
let mut times = [ CLIPPY_DRIVER_PATH , CARGO_CLIPPY_PATH ] . iter ( ) . map ( |p| {
505
508
std:: fs:: metadata ( p)
@@ -533,15 +536,13 @@ pub fn run(clap_config: &ArgMatches) {
533
536
// refresh the logs
534
537
if lintcheck_needs_rerun ( & config. lintcheck_results_path ) {
535
538
let shared_target_dir = "target/lintcheck/shared_target_dir" ;
536
- match std:: fs:: metadata ( & shared_target_dir) {
537
- Ok ( metadata) => {
538
- if metadata. is_dir ( ) {
539
- println ! ( "Clippy is newer than lint check logs, clearing lintcheck shared target dir..." ) ;
540
- std:: fs:: remove_dir_all ( & shared_target_dir)
541
- . expect ( "failed to remove target/lintcheck/shared_target_dir" ) ;
542
- }
543
- } ,
544
- Err ( _) => { /* dir probably does not exist, don't remove anything */ } ,
539
+ // if we get an Err here, the shared target dir probably does simply not exist
540
+ if let Ok ( metadata) = std:: fs:: metadata ( & shared_target_dir) {
541
+ if metadata. is_dir ( ) {
542
+ println ! ( "Clippy is newer than lint check logs, clearing lintcheck shared target dir..." ) ;
543
+ std:: fs:: remove_dir_all ( & shared_target_dir)
544
+ . expect ( "failed to remove target/lintcheck/shared_target_dir" ) ;
545
+ }
545
546
}
546
547
}
547
548
@@ -660,7 +661,7 @@ pub fn run(clap_config: &ArgMatches) {
660
661
}
661
662
662
663
/// read the previous stats from the lintcheck-log file
663
- fn read_stats_from_file ( file_path : & PathBuf ) -> HashMap < String , usize > {
664
+ fn read_stats_from_file ( file_path : & Path ) -> HashMap < String , usize > {
664
665
let file_content: String = match std:: fs:: read_to_string ( file_path) . ok ( ) {
665
666
Some ( content) => content,
666
667
None => {
@@ -678,9 +679,9 @@ fn read_stats_from_file(file_path: &PathBuf) -> HashMap<String, usize> {
678
679
let stats_lines = & lines[ start + 1 ..=end - 1 ] ;
679
680
680
681
stats_lines
681
- . into_iter ( )
682
+ . iter ( )
682
683
. map ( |line| {
683
- let mut spl = line. split ( " " ) . into_iter ( ) ;
684
+ let mut spl = line. split ( ' ' ) ;
684
685
(
685
686
spl. next ( ) . unwrap ( ) . to_string ( ) ,
686
687
spl. next ( ) . unwrap ( ) . parse :: < usize > ( ) . unwrap ( ) ,
0 commit comments