File tree Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -3,9 +3,14 @@ use std::path::PathBuf;
3
3
4
4
#[ derive( Clone , Debug , Parser ) ]
5
5
pub ( crate ) struct LintcheckConfig {
6
- /// Number of threads to use, 0 automatic choice
7
- #[ clap( long = "jobs" , short = 'j' , value_name = "N" , default_value_t = 1 ) ]
8
- pub max_jobs : usize ,
6
+ /// Always defined after the config phase
7
+ #[ clap(
8
+ long = "jobs" ,
9
+ short = 'j' ,
10
+ value_name = "N" ,
11
+ help = "Number of threads to use (default: all unless --fix or --recursive)"
12
+ ) ]
13
+ pub max_jobs : Option < usize > ,
9
14
/// Set the path for a crates.toml where lintcheck should read the sources from
10
15
#[ clap(
11
16
long = "crates-toml" ,
@@ -50,9 +55,12 @@ impl LintcheckConfig {
50
55
) ) ;
51
56
52
57
// look at the --threads arg, if 0 is passed, use the threads count
53
- if config. max_jobs == 0 {
54
- // automatic choice
55
- config. max_jobs = std:: thread:: available_parallelism ( ) . map_or ( 1 , |n| n. get ( ) ) ;
58
+ if config. max_jobs . is_none ( ) {
59
+ config. max_jobs = Some ( if config. fix || config. recursive {
60
+ 1
61
+ } else {
62
+ std:: thread:: available_parallelism ( ) . map_or ( 1 , |n| n. get ( ) )
63
+ } ) ;
56
64
} ;
57
65
58
66
for lint_name in & mut config. lint_filter {
Original file line number Diff line number Diff line change @@ -317,10 +317,10 @@ impl Crate {
317
317
// advance the atomic index by one
318
318
let index = target_dir_index. fetch_add ( 1 , Ordering :: SeqCst ) ;
319
319
// "loop" the index within 0..thread_limit
320
- let thread_index = index % config. max_jobs ;
320
+ let thread_index = index % config. max_jobs . unwrap ( ) ;
321
321
let perc = ( index * 100 ) / total_crates_to_lint;
322
322
323
- if config. max_jobs == 1 {
323
+ if config. max_jobs . unwrap ( ) == 1 {
324
324
println ! (
325
325
"{index}/{total_crates_to_lint} {perc}% Linting {} {}" ,
326
326
& self . name, & self . version
@@ -627,7 +627,7 @@ fn main() {
627
627
// order to achieve some kind of parallelism
628
628
629
629
rayon:: ThreadPoolBuilder :: new ( )
630
- . num_threads ( config. max_jobs )
630
+ . num_threads ( config. max_jobs . unwrap ( ) )
631
631
. build_global ( )
632
632
. unwrap ( ) ;
633
633
You can’t perform that action at this time.
0 commit comments