@@ -70,15 +70,15 @@ macro_rules! create_config {
70
70
//
71
71
// - $i: the ident name of the option
72
72
// - $ty: the type of the option value
73
- // - $def: the default value of the option
74
73
// - $stb: true if the option is stable
75
74
// - $dstring: description of the option
76
- ( $( $i: ident: $ty: ty, $def : expr , $ stb: expr, $( $dstring: expr ) ,+ ) ;+ $( ; ) * ) => (
75
+ ( $( $i: ident: $ty: ty, $stb: expr, $( $dstring: expr ) ,+ ) ;+ $( ; ) * ) => (
77
76
#[ cfg( test) ]
78
77
use std:: collections:: HashSet ;
79
78
use std:: io:: Write ;
80
79
81
80
use serde:: { Deserialize , Serialize } ;
81
+ use $crate:: config:: style_edition:: StyleEditionDefault ;
82
82
83
83
#[ derive( Clone ) ]
84
84
#[ allow( unreachable_pub) ]
@@ -89,7 +89,7 @@ macro_rules! create_config {
89
89
// - 1: true if the option was manually initialized
90
90
// - 2: the option value
91
91
// - 3: true if the option is unstable
92
- $( $i: ( Cell <bool >, bool , $ty, bool ) ) ,+
92
+ $( $i: ( Cell <bool >, bool , < $ty as StyleEditionDefault > :: ConfigType , bool ) ) ,+
93
93
}
94
94
95
95
// Just like the Config struct but with each property wrapped
@@ -100,7 +100,7 @@ macro_rules! create_config {
100
100
#[ derive( Deserialize , Serialize , Clone ) ]
101
101
#[ allow( unreachable_pub) ]
102
102
pub struct PartialConfig {
103
- $( pub $i: Option <$ty>) ,+
103
+ $( pub $i: Option << $ty as StyleEditionDefault > :: ConfigType >) ,+
104
104
}
105
105
106
106
// Macro hygiene won't allow us to make `set_$i()` methods on Config
@@ -114,7 +114,7 @@ macro_rules! create_config {
114
114
impl <' a> ConfigSetter <' a> {
115
115
$(
116
116
#[ allow( unreachable_pub) ]
117
- pub fn $i( & mut self , value: $ty) {
117
+ pub fn $i( & mut self , value: < $ty as StyleEditionDefault > :: ConfigType ) {
118
118
( self . 0 ) . $i. 2 = value;
119
119
match stringify!( $i) {
120
120
"max_width"
@@ -153,12 +153,28 @@ macro_rules! create_config {
153
153
impl Config {
154
154
$(
155
155
#[ allow( unreachable_pub) ]
156
- pub fn $i( & self ) -> $ty {
156
+ pub fn $i( & self ) -> < $ty as StyleEditionDefault > :: ConfigType {
157
157
self . $i. 0 . set( true ) ;
158
158
self . $i. 2 . clone( )
159
159
}
160
160
) +
161
161
162
+ #[ allow( unreachable_pub) ]
163
+ pub fn default_with_style_edition( style_edition: StyleEdition ) -> Config {
164
+ Config {
165
+ $(
166
+ $i: (
167
+ Cell :: new( false ) ,
168
+ false ,
169
+ <$ty as StyleEditionDefault >:: style_edition_default(
170
+ style_edition
171
+ ) ,
172
+ $stb
173
+ ) ,
174
+ ) +
175
+ }
176
+ }
177
+
162
178
#[ allow( unreachable_pub) ]
163
179
pub fn set( & mut self ) -> ConfigSetter <' _> {
164
180
ConfigSetter ( self )
@@ -212,7 +228,9 @@ macro_rules! create_config {
212
228
pub fn is_valid_key_val( key: & str , val: & str ) -> bool {
213
229
match key {
214
230
$(
215
- stringify!( $i) => val. parse:: <$ty>( ) . is_ok( ) ,
231
+ stringify!( $i) => {
232
+ val. parse:: <<$ty as StyleEditionDefault >:: ConfigType >( ) . is_ok( )
233
+ }
216
234
) +
217
235
_ => false ,
218
236
}
@@ -246,11 +264,15 @@ macro_rules! create_config {
246
264
match key {
247
265
$(
248
266
stringify!( $i) => {
249
- let option_value = val. parse:: <$ty>( )
250
- . expect( & format!( "Failed to parse override for {} (\" {}\" ) as a {}" ,
251
- stringify!( $i) ,
252
- val,
253
- stringify!( $ty) ) ) ;
267
+ let value = val. parse:: <<$ty as StyleEditionDefault >:: ConfigType >( )
268
+ . expect(
269
+ & format!(
270
+ "Failed to parse override for {} (\" {}\" ) as a {}" ,
271
+ stringify!( $i) ,
272
+ val,
273
+ stringify!( <$ty as StyleEditionDefault >:: ConfigType )
274
+ )
275
+ ) ;
254
276
255
277
// Users are currently allowed to set unstable
256
278
// options/variants via the `--config` options override.
@@ -261,7 +283,7 @@ macro_rules! create_config {
261
283
// For now, do not validate whether the option or value is stable,
262
284
// just always set it.
263
285
self . $i. 1 = true ;
264
- self . $i. 2 = option_value ;
286
+ self . $i. 2 = value ;
265
287
}
266
288
) +
267
289
_ => panic!( "Unknown config key in override: {}" , key)
@@ -301,6 +323,7 @@ macro_rules! create_config {
301
323
302
324
#[ allow( unreachable_pub) ]
303
325
pub fn print_docs( out: & mut dyn Write , include_unstable: bool ) {
326
+ let style_edition = StyleEdition :: Edition2015 ;
304
327
use std:: cmp;
305
328
let max = 0 ;
306
329
$( let max = cmp:: max( max, stringify!( $i) . len( ) +1 ) ; ) +
@@ -317,14 +340,17 @@ macro_rules! create_config {
317
340
}
318
341
name_out. push_str( name_raw) ;
319
342
name_out. push( ' ' ) ;
320
- let mut default_str = format!( "{}" , $def) ;
343
+ let default_value = <$ty as StyleEditionDefault >:: style_edition_default(
344
+ style_edition
345
+ ) ;
346
+ let mut default_str = format!( "{}" , default_value) ;
321
347
if default_str. is_empty( ) {
322
348
default_str = String :: from( "\" \" " ) ;
323
349
}
324
350
writeln!( out,
325
351
"{}{} Default: {}{}" ,
326
352
name_out,
327
- <$ty>:: doc_hint( ) ,
353
+ << $ty as StyleEditionDefault > :: ConfigType >:: doc_hint( ) ,
328
354
default_str,
329
355
if !$stb { " (unstable)" } else { "" } ) . unwrap( ) ;
330
356
$(
@@ -480,9 +506,13 @@ macro_rules! create_config {
480
506
#[ allow( unreachable_pub) ]
481
507
/// Returns `true` if the config key was explicitly set and is the default value.
482
508
pub fn is_default( & self , key: & str ) -> bool {
509
+ let style_edition = StyleEdition :: Edition2015 ;
483
510
$(
511
+ let default_value = <$ty as StyleEditionDefault >:: style_edition_default(
512
+ style_edition
513
+ ) ;
484
514
if let stringify!( $i) = key {
485
- return self . $i. 1 && self . $i. 2 == $def ;
515
+ return self . $i. 1 && self . $i. 2 == default_value ;
486
516
}
487
517
) +
488
518
false
@@ -492,11 +522,7 @@ macro_rules! create_config {
492
522
// Template for the default configuration
493
523
impl Default for Config {
494
524
fn default ( ) -> Config {
495
- Config {
496
- $(
497
- $i: ( Cell :: new( false ) , false , $def, $stb) ,
498
- ) +
499
- }
525
+ Config :: default_with_style_edition( StyleEdition :: Edition2015 )
500
526
}
501
527
}
502
528
)
0 commit comments