@@ -138,7 +138,7 @@ impl Cfg {
138
138
139
139
/// Renders the configuration for human display, as a short HTML description.
140
140
pub ( crate ) fn render_short_html ( & self ) -> String {
141
- let mut msg = ShortHtml ( self ) . to_string ( ) ;
141
+ let mut msg = Html ( self , true ) . to_string ( ) ;
142
142
if self . should_capitalize_first_letter ( ) {
143
143
if let Some ( i) = msg. find ( |c : char | c. is_ascii_alphanumeric ( ) ) {
144
144
msg[ i .. i+1 ] . make_ascii_uppercase ( ) ;
@@ -155,7 +155,7 @@ impl Cfg {
155
155
"on"
156
156
} ;
157
157
158
- let mut msg = format ! ( "This is supported {} <strong>{}</strong>" , on, Html ( self ) ) ;
158
+ let mut msg = format ! ( "This is supported {} <strong>{}</strong>" , on, Html ( self , false ) ) ;
159
159
if self . should_append_only_to_description ( ) {
160
160
msg. push_str ( " only" ) ;
161
161
}
@@ -265,7 +265,9 @@ impl ops::BitOr for Cfg {
265
265
}
266
266
}
267
267
268
- struct Html < ' a > ( & ' a Cfg ) ;
268
+ /// Pretty-print wrapper for a `Cfg`. Also indicates whether the "short-form" rendering should be
269
+ /// used.
270
+ struct Html < ' a > ( & ' a Cfg , bool ) ;
269
271
270
272
fn write_with_opt_paren < T : fmt:: Display > (
271
273
fmt : & mut fmt:: Formatter ,
@@ -295,12 +297,12 @@ impl<'a> fmt::Display for Html<'a> {
295
297
} ;
296
298
for ( i, sub_cfg) in sub_cfgs. iter ( ) . enumerate ( ) {
297
299
fmt. write_str ( if i == 0 { "neither " } else { separator } ) ?;
298
- write_with_opt_paren ( fmt, !sub_cfg. is_all ( ) , Html ( sub_cfg) ) ?;
300
+ write_with_opt_paren ( fmt, !sub_cfg. is_all ( ) , Html ( sub_cfg, self . 1 ) ) ?;
299
301
}
300
302
Ok ( ( ) )
301
303
}
302
- ref simple @ Cfg :: Cfg ( ..) => write ! ( fmt, "non-{}" , Html ( simple) ) ,
303
- ref c => write ! ( fmt, "not ({})" , Html ( c) ) ,
304
+ ref simple @ Cfg :: Cfg ( ..) => write ! ( fmt, "non-{}" , Html ( simple, self . 1 ) ) ,
305
+ ref c => write ! ( fmt, "not ({})" , Html ( c, self . 1 ) ) ,
304
306
} ,
305
307
306
308
Cfg :: Any ( ref sub_cfgs) => {
@@ -313,7 +315,7 @@ impl<'a> fmt::Display for Html<'a> {
313
315
if i != 0 {
314
316
fmt. write_str ( separator) ?;
315
317
}
316
- write_with_opt_paren ( fmt, !sub_cfg. is_all ( ) , Html ( sub_cfg) ) ?;
318
+ write_with_opt_paren ( fmt, !sub_cfg. is_all ( ) , Html ( sub_cfg, self . 1 ) ) ?;
317
319
}
318
320
Ok ( ( ) )
319
321
} ,
@@ -323,7 +325,7 @@ impl<'a> fmt::Display for Html<'a> {
323
325
if i != 0 {
324
326
fmt. write_str ( " and " ) ?;
325
327
}
326
- write_with_opt_paren ( fmt, !sub_cfg. is_simple ( ) , Html ( sub_cfg) ) ?;
328
+ write_with_opt_paren ( fmt, !sub_cfg. is_simple ( ) , Html ( sub_cfg, self . 1 ) ) ?;
327
329
}
328
330
Ok ( ( ) )
329
331
} ,
@@ -390,7 +392,11 @@ impl<'a> fmt::Display for Html<'a> {
390
392
( "target_endian" , Some ( endian) ) => return write ! ( fmt, "{}-endian" , endian) ,
391
393
( "target_pointer_width" , Some ( bits) ) => return write ! ( fmt, "{}-bit" , bits) ,
392
394
( "target_feature" , Some ( feat) ) =>
393
- return write ! ( fmt, "target feature <code>{}</code>" , feat) ,
395
+ if self . 1 {
396
+ return write ! ( fmt, "<code>{}</code>" , feat) ;
397
+ } else {
398
+ return write ! ( fmt, "target feature <code>{}</code>" , feat) ;
399
+ } ,
394
400
_ => "" ,
395
401
} ;
396
402
if !human_readable. is_empty ( ) {
@@ -405,19 +411,6 @@ impl<'a> fmt::Display for Html<'a> {
405
411
}
406
412
}
407
413
408
- struct ShortHtml < ' a > ( & ' a Cfg ) ;
409
-
410
- impl < ' a > fmt:: Display for ShortHtml < ' a > {
411
- fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
412
- match * self . 0 {
413
- Cfg :: Cfg ( ref name, Some ( ref vendor) ) if name == & "target_feature" => {
414
- write ! ( fmt, "<code>{}</code>" , vendor)
415
- } ,
416
- ref cfg => write ! ( fmt, "{}" , Html ( cfg) ) ,
417
- }
418
- }
419
- }
420
-
421
414
#[ cfg( test) ]
422
415
mod test {
423
416
use super :: Cfg ;
@@ -740,6 +733,13 @@ mod test {
740
733
name_value_cfg( "target_feature" , "sse2" ) . render_short_html( ) ,
741
734
"<code>sse2</code>"
742
735
) ;
736
+ assert_eq ! (
737
+ (
738
+ name_value_cfg( "target_arch" , "x86_64" ) &
739
+ name_value_cfg( "target_feature" , "sse2" )
740
+ ) . render_short_html( ) ,
741
+ "x86-64 and <code>sse2</code>"
742
+ ) ;
743
743
} )
744
744
}
745
745
@@ -818,6 +818,14 @@ mod test {
818
818
name_value_cfg( "target_feature" , "sse2" ) . render_long_html( ) ,
819
819
"This is supported with <strong>target feature <code>sse2</code></strong> only."
820
820
) ;
821
+ assert_eq ! (
822
+ (
823
+ name_value_cfg( "target_arch" , "x86_64" ) &
824
+ name_value_cfg( "target_feature" , "sse2" )
825
+ ) . render_long_html( ) ,
826
+ "This is supported on <strong>x86-64 and target feature \
827
+ <code>sse2</code></strong> only."
828
+ ) ;
821
829
} )
822
830
}
823
831
}
0 commit comments