@@ -83,14 +83,20 @@ macro_rules! create_config {
83
83
#[ derive( Clone ) ]
84
84
#[ allow( unreachable_pub) ]
85
85
pub struct Config {
86
- // For each config item, we store:
87
- //
88
- // - 0: true if the value has been access
89
- // - 1: true if the option was manually initialized
90
- // - 2: the option value
91
- // - 3: true if the option is stable
92
- // - 4: true if the option was set manually from a CLI flag
93
- $( $i: ( Cell <bool >, bool , <$ty as StyleEditionDefault >:: ConfigType , bool , bool ) ) ,+
86
+ $( $i: ConfigOption <<$ty as StyleEditionDefault >:: ConfigType >) ,+
87
+ }
88
+
89
+ #[ derive( Clone ) ]
90
+ struct ConfigOption <T > {
91
+ value: T ,
92
+ /// `true` if the value has been accessed
93
+ is_used: std:: cell:: Cell <bool >,
94
+ /// `true` if the option is stable
95
+ is_stable: bool ,
96
+ /// `true` if the option was manually initialized
97
+ was_set: bool ,
98
+ /// `true` if the option was set manually from a CLI flag
99
+ was_set_cli: bool ,
94
100
}
95
101
96
102
// Just like the Config struct but with each property wrapped
@@ -116,7 +122,7 @@ macro_rules! create_config {
116
122
$(
117
123
#[ allow( unreachable_pub) ]
118
124
pub fn $i( & mut self , value: <$ty as StyleEditionDefault >:: ConfigType ) {
119
- ( self . 0 ) . $i. 2 = value;
125
+ ( self . 0 ) . $i. value = value;
120
126
match stringify!( $i) {
121
127
"max_width"
122
128
| "use_small_heuristics"
@@ -145,8 +151,8 @@ macro_rules! create_config {
145
151
$(
146
152
#[ allow( unreachable_pub) ]
147
153
pub fn $i( & mut self , value: <$ty as StyleEditionDefault >:: ConfigType ) {
148
- ( self . 0 ) . $i. 2 = value;
149
- ( self . 0 ) . $i. 4 = true ;
154
+ ( self . 0 ) . $i. value = value;
155
+ ( self . 0 ) . $i. was_set_cli = true ;
150
156
match stringify!( $i) {
151
157
"max_width"
152
158
| "use_small_heuristics"
@@ -177,7 +183,7 @@ macro_rules! create_config {
177
183
$(
178
184
#[ allow( unreachable_pub) ]
179
185
pub fn $i( & self ) -> bool {
180
- ( self . 0 ) . $i. 1
186
+ ( self . 0 ) . $i. was_set
181
187
}
182
188
) +
183
189
}
@@ -191,7 +197,7 @@ macro_rules! create_config {
191
197
$(
192
198
#[ allow( unreachable_pub) ]
193
199
pub fn $i( & self ) -> bool {
194
- ( self . 0 ) . $i. 4
200
+ ( self . 0 ) . $i. was_set_cli
195
201
}
196
202
) +
197
203
}
@@ -200,24 +206,24 @@ macro_rules! create_config {
200
206
$(
201
207
#[ allow( unreachable_pub) ]
202
208
pub fn $i( & self ) -> <$ty as StyleEditionDefault >:: ConfigType {
203
- self . $i. 0 . set( true ) ;
204
- self . $i. 2 . clone( )
209
+ self . $i. is_used . set( true ) ;
210
+ self . $i. value . clone( )
205
211
}
206
212
) +
207
213
208
214
#[ allow( unreachable_pub) ]
209
215
pub ( super ) fn default_with_style_edition( style_edition: StyleEdition ) -> Config {
210
216
Config {
211
217
$(
212
- $i: (
213
- Cell :: new( false ) ,
214
- false ,
215
- <$ty as StyleEditionDefault >:: style_edition_default(
216
- style_edition
217
- ) ,
218
- $stb,
219
- false ,
218
+ $i: ConfigOption {
219
+ is_used: Cell :: new( false ) ,
220
+ was_set: false ,
221
+ value: <$ty as StyleEditionDefault >:: style_edition_default(
222
+ style_edition
220
223
) ,
224
+ is_stable: $stb,
225
+ was_set_cli: false ,
226
+ } ,
221
227
) +
222
228
}
223
229
}
@@ -245,12 +251,11 @@ macro_rules! create_config {
245
251
fn fill_from_parsed_config( mut self , parsed: PartialConfig , dir: & Path ) -> Config {
246
252
$(
247
253
if let Some ( option_value) = parsed. $i {
248
- let option_stable = self . $i. 3 ;
249
254
if $crate:: config:: config_type:: is_stable_option_and_value(
250
- stringify!( $i) , option_stable , & option_value
255
+ stringify!( $i) , self . $i . is_stable , & option_value
251
256
) {
252
- self . $i. 1 = true ;
253
- self . $i. 2 = option_value;
257
+ self . $i. was_set = true ;
258
+ self . $i. value = option_value;
254
259
}
255
260
}
256
261
) +
@@ -298,8 +303,8 @@ macro_rules! create_config {
298
303
pub fn used_options( & self ) -> PartialConfig {
299
304
PartialConfig {
300
305
$(
301
- $i: if self . $i. 0 . get( ) {
302
- Some ( self . $i. 2 . clone( ) )
306
+ $i: if self . $i. is_used . get( ) {
307
+ Some ( self . $i. value . clone( ) )
303
308
} else {
304
309
None
305
310
} ,
@@ -311,7 +316,7 @@ macro_rules! create_config {
311
316
pub fn all_options( & self ) -> PartialConfig {
312
317
PartialConfig {
313
318
$(
314
- $i: Some ( self . $i. 2 . clone( ) ) ,
319
+ $i: Some ( self . $i. value . clone( ) ) ,
315
320
) +
316
321
}
317
322
}
@@ -340,8 +345,8 @@ macro_rules! create_config {
340
345
//
341
346
// For now, do not validate whether the option or value is stable,
342
347
// just always set it.
343
- self . $i. 1 = true ;
344
- self . $i. 2 = value;
348
+ self . $i. was_set = true ;
349
+ self . $i. value = value;
345
350
}
346
351
) +
347
352
_ => panic!( "Unknown config key in override: {}" , key)
@@ -422,7 +427,7 @@ macro_rules! create_config {
422
427
}
423
428
424
429
fn set_width_heuristics( & mut self , heuristics: WidthHeuristics ) {
425
- let max_width = self . max_width. 2 ;
430
+ let max_width = self . max_width. value ;
426
431
let get_width_value = |
427
432
was_set: bool ,
428
433
override_value: usize ,
@@ -444,73 +449,73 @@ macro_rules! create_config {
444
449
} ;
445
450
446
451
let fn_call_width = get_width_value(
447
- self . was_set ( ) . fn_call_width( ) ,
448
- self . fn_call_width. 2 ,
452
+ self . fn_call_width. was_set ,
453
+ self . fn_call_width. value ,
449
454
heuristics. fn_call_width,
450
455
"fn_call_width" ,
451
456
) ;
452
- self . fn_call_width. 2 = fn_call_width;
457
+ self . fn_call_width. value = fn_call_width;
453
458
454
459
let attr_fn_like_width = get_width_value(
455
- self . was_set ( ) . attr_fn_like_width( ) ,
456
- self . attr_fn_like_width. 2 ,
460
+ self . attr_fn_like_width. was_set ,
461
+ self . attr_fn_like_width. value ,
457
462
heuristics. attr_fn_like_width,
458
463
"attr_fn_like_width" ,
459
464
) ;
460
- self . attr_fn_like_width. 2 = attr_fn_like_width;
465
+ self . attr_fn_like_width. value = attr_fn_like_width;
461
466
462
467
let struct_lit_width = get_width_value(
463
- self . was_set ( ) . struct_lit_width( ) ,
464
- self . struct_lit_width. 2 ,
468
+ self . struct_lit_width. was_set ,
469
+ self . struct_lit_width. value ,
465
470
heuristics. struct_lit_width,
466
471
"struct_lit_width" ,
467
472
) ;
468
- self . struct_lit_width. 2 = struct_lit_width;
473
+ self . struct_lit_width. value = struct_lit_width;
469
474
470
475
let struct_variant_width = get_width_value(
471
- self . was_set ( ) . struct_variant_width( ) ,
472
- self . struct_variant_width. 2 ,
476
+ self . struct_variant_width. was_set ,
477
+ self . struct_variant_width. value ,
473
478
heuristics. struct_variant_width,
474
479
"struct_variant_width" ,
475
480
) ;
476
- self . struct_variant_width. 2 = struct_variant_width;
481
+ self . struct_variant_width. value = struct_variant_width;
477
482
478
483
let array_width = get_width_value(
479
- self . was_set ( ) . array_width( ) ,
480
- self . array_width. 2 ,
484
+ self . array_width. was_set ,
485
+ self . array_width. value ,
481
486
heuristics. array_width,
482
487
"array_width" ,
483
488
) ;
484
- self . array_width. 2 = array_width;
489
+ self . array_width. value = array_width;
485
490
486
491
let chain_width = get_width_value(
487
- self . was_set ( ) . chain_width( ) ,
488
- self . chain_width. 2 ,
492
+ self . chain_width. was_set ,
493
+ self . chain_width. value ,
489
494
heuristics. chain_width,
490
495
"chain_width" ,
491
496
) ;
492
- self . chain_width. 2 = chain_width;
497
+ self . chain_width. value = chain_width;
493
498
494
499
let single_line_if_else_max_width = get_width_value(
495
- self . was_set ( ) . single_line_if_else_max_width( ) ,
496
- self . single_line_if_else_max_width. 2 ,
500
+ self . single_line_if_else_max_width. was_set ,
501
+ self . single_line_if_else_max_width. value ,
497
502
heuristics. single_line_if_else_max_width,
498
503
"single_line_if_else_max_width" ,
499
504
) ;
500
- self . single_line_if_else_max_width. 2 = single_line_if_else_max_width;
505
+ self . single_line_if_else_max_width. value = single_line_if_else_max_width;
501
506
502
507
let single_line_let_else_max_width = get_width_value(
503
- self . was_set ( ) . single_line_let_else_max_width( ) ,
504
- self . single_line_let_else_max_width. 2 ,
508
+ self . single_line_let_else_max_width. was_set ,
509
+ self . single_line_let_else_max_width. value ,
505
510
heuristics. single_line_let_else_max_width,
506
511
"single_line_let_else_max_width" ,
507
512
) ;
508
- self . single_line_let_else_max_width. 2 = single_line_let_else_max_width;
513
+ self . single_line_let_else_max_width. value = single_line_let_else_max_width;
509
514
}
510
515
511
516
fn set_heuristics( & mut self ) {
512
- let max_width = self . max_width. 2 ;
513
- match self . use_small_heuristics. 2 {
517
+ let max_width = self . max_width. value ;
518
+ match self . use_small_heuristics. value {
514
519
Heuristics :: Default =>
515
520
self . set_width_heuristics( WidthHeuristics :: scaled( max_width) ) ,
516
521
Heuristics :: Max => self . set_width_heuristics( WidthHeuristics :: set( max_width) ) ,
@@ -519,17 +524,17 @@ macro_rules! create_config {
519
524
}
520
525
521
526
fn set_ignore( & mut self , dir: & Path ) {
522
- self . ignore. 2 . add_prefix( dir) ;
527
+ self . ignore. value . add_prefix( dir) ;
523
528
}
524
529
525
530
fn set_merge_imports( & mut self ) {
526
- if self . was_set ( ) . merge_imports( ) {
531
+ if self . merge_imports. was_set {
527
532
eprintln!(
528
533
"Warning: the `merge_imports` option is deprecated. \
529
534
Use `imports_granularity=\" Crate\" ` instead"
530
535
) ;
531
- if !self . was_set ( ) . imports_granularity( ) {
532
- self . imports_granularity. 2 = if self . merge_imports( ) {
536
+ if !self . imports_granularity. was_set {
537
+ self . imports_granularity. value = if self . merge_imports( ) {
533
538
ImportGranularity :: Crate
534
539
} else {
535
540
ImportGranularity :: Preserve
@@ -539,31 +544,31 @@ macro_rules! create_config {
539
544
}
540
545
541
546
fn set_fn_args_layout( & mut self ) {
542
- if self . was_set ( ) . fn_args_layout( ) {
547
+ if self . fn_args_layout. was_set {
543
548
eprintln!(
544
549
"Warning: the `fn_args_layout` option is deprecated. \
545
550
Use `fn_params_layout`. instead"
546
551
) ;
547
- if !self . was_set ( ) . fn_params_layout( ) {
548
- self . fn_params_layout. 2 = self . fn_args_layout( ) ;
552
+ if !self . fn_params_layout. was_set {
553
+ self . fn_params_layout. value = self . fn_args_layout( ) ;
549
554
}
550
555
}
551
556
}
552
557
553
558
fn set_hide_parse_errors( & mut self ) {
554
- if self . was_set ( ) . hide_parse_errors( ) {
559
+ if self . hide_parse_errors. was_set {
555
560
eprintln!(
556
561
"Warning: the `hide_parse_errors` option is deprecated. \
557
562
Use `show_parse_errors` instead"
558
563
) ;
559
- if !self . was_set ( ) . show_parse_errors( ) {
560
- self . show_parse_errors. 2 = self . hide_parse_errors( ) ;
564
+ if !self . show_parse_errors. was_set {
565
+ self . show_parse_errors. value = self . hide_parse_errors( ) ;
561
566
}
562
567
}
563
568
}
564
569
565
570
fn set_version( & mut self ) {
566
- if !self . was_set ( ) . version( ) {
571
+ if !self . version. was_set {
567
572
return ;
568
573
}
569
574
@@ -572,7 +577,7 @@ macro_rules! create_config {
572
577
Use `style_edition` instead."
573
578
) ;
574
579
575
- if self . was_set ( ) . style_edition( ) || self . was_set_cli ( ) . style_edition( ) {
580
+ if self . style_edition. was_set || self . style_edition. was_set_cli {
576
581
eprintln!(
577
582
"Warning: the deprecated `version` option was \
578
583
used in conjunction with the `style_edition` \
@@ -591,7 +596,7 @@ macro_rules! create_config {
591
596
style_edition
592
597
) ;
593
598
if let stringify!( $i) = key {
594
- return self . $i. 1 && self . $i. 2 == default_value;
599
+ return self . $i. was_set && self . $i. value == default_value;
595
600
}
596
601
) +
597
602
false
0 commit comments