@@ -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"
@@ -152,12 +152,28 @@ macro_rules! create_config {
152
152
impl Config {
153
153
$(
154
154
#[ allow( unreachable_pub) ]
155
- pub fn $i( & self ) -> $ty {
155
+ pub fn $i( & self ) -> < $ty as StyleEditionDefault > :: ConfigType {
156
156
self . $i. 0 . set( true ) ;
157
157
self . $i. 2 . clone( )
158
158
}
159
159
) +
160
160
161
+ #[ allow( unreachable_pub) ]
162
+ pub fn deafult_with_style_edition( style_edition: StyleEdition ) -> Config {
163
+ Config {
164
+ $(
165
+ $i: (
166
+ Cell :: new( false ) ,
167
+ false ,
168
+ <$ty as StyleEditionDefault >:: style_edition_default(
169
+ style_edition
170
+ ) ,
171
+ $stb
172
+ ) ,
173
+ ) +
174
+ }
175
+ }
176
+
161
177
#[ allow( unreachable_pub) ]
162
178
pub fn set( & mut self ) -> ConfigSetter <' _> {
163
179
ConfigSetter ( self )
@@ -210,7 +226,9 @@ macro_rules! create_config {
210
226
pub fn is_valid_key_val( key: & str , val: & str ) -> bool {
211
227
match key {
212
228
$(
213
- stringify!( $i) => val. parse:: <$ty>( ) . is_ok( ) ,
229
+ stringify!( $i) => {
230
+ val. parse:: <<$ty as StyleEditionDefault >:: ConfigType >( ) . is_ok( )
231
+ }
214
232
) +
215
233
_ => false ,
216
234
}
@@ -244,11 +262,15 @@ macro_rules! create_config {
244
262
match key {
245
263
$(
246
264
stringify!( $i) => {
247
- let option_value = val. parse:: <$ty>( )
248
- . expect( & format!( "Failed to parse override for {} (\" {}\" ) as a {}" ,
249
- stringify!( $i) ,
250
- val,
251
- stringify!( $ty) ) ) ;
265
+ let value = val. parse:: <<$ty as StyleEditionDefault >:: ConfigType >( )
266
+ . expect(
267
+ & format!(
268
+ "Failed to parse override for {} (\" {}\" ) as a {}" ,
269
+ stringify!( $i) ,
270
+ val,
271
+ stringify!( <$ty as StyleEditionDefault >:: ConfigType )
272
+ )
273
+ ) ;
252
274
253
275
// Users are currently allowed to set unstable
254
276
// options/variants via the `--config` options override.
@@ -259,7 +281,7 @@ macro_rules! create_config {
259
281
// For now, do not validate whether the option or value is stable,
260
282
// just always set it.
261
283
self . $i. 1 = true ;
262
- self . $i. 2 = option_value ;
284
+ self . $i. 2 = value ;
263
285
}
264
286
) +
265
287
_ => panic!( "Unknown config key in override: {}" , key)
@@ -297,6 +319,7 @@ macro_rules! create_config {
297
319
298
320
#[ allow( unreachable_pub) ]
299
321
pub fn print_docs( out: & mut dyn Write , include_unstable: bool ) {
322
+ let style_edition = StyleEdition :: Edition2015 ;
300
323
use std:: cmp;
301
324
let max = 0 ;
302
325
$( let max = cmp:: max( max, stringify!( $i) . len( ) +1 ) ; ) +
@@ -313,14 +336,17 @@ macro_rules! create_config {
313
336
}
314
337
name_out. push_str( name_raw) ;
315
338
name_out. push( ' ' ) ;
316
- let mut default_str = format!( "{}" , $def) ;
339
+ let default = <$ty as StyleEditionDefault >:: style_edition_default(
340
+ style_edition
341
+ ) ;
342
+ let mut default_str = format!( "{}" , default ) ;
317
343
if default_str. is_empty( ) {
318
344
default_str = String :: from( "\" \" " ) ;
319
345
}
320
346
writeln!( out,
321
347
"{}{} Default: {}{}" ,
322
348
name_out,
323
- <$ty>:: doc_hint( ) ,
349
+ << $ty as StyleEditionDefault > :: ConfigType >:: doc_hint( ) ,
324
350
default_str,
325
351
if !$stb { " (unstable)" } else { "" } ) . unwrap( ) ;
326
352
$(
@@ -464,9 +490,13 @@ macro_rules! create_config {
464
490
#[ allow( unreachable_pub) ]
465
491
/// Returns `true` if the config key was explicitly set and is the default value.
466
492
pub fn is_default( & self , key: & str ) -> bool {
493
+ let style_edition = StyleEdition :: Edition2015 ;
467
494
$(
495
+ let default = <$ty as StyleEditionDefault >:: style_edition_default(
496
+ style_edition
497
+ ) ;
468
498
if let stringify!( $i) = key {
469
- return self . $i. 1 && self . $i. 2 == $def ;
499
+ return self . $i. 1 && self . $i. 2 == default ;
470
500
}
471
501
) +
472
502
false
@@ -476,11 +506,7 @@ macro_rules! create_config {
476
506
// Template for the default configuration
477
507
impl Default for Config {
478
508
fn default ( ) -> Config {
479
- Config {
480
- $(
481
- $i: ( Cell :: new( false ) , false , $def, $stb) ,
482
- ) +
483
- }
509
+ Config :: deafult_with_style_edition( StyleEdition :: Edition2015 )
484
510
}
485
511
}
486
512
)
0 commit comments