@@ -138,7 +138,7 @@ impl Cfg {
138138
139139 /// Renders the configuration for human display, as a short HTML description.
140140 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 ( ) ;
142142 if self . should_capitalize_first_letter ( ) {
143143 if let Some ( i) = msg. find ( |c : char | c. is_ascii_alphanumeric ( ) ) {
144144 msg[ i .. i+1 ] . make_ascii_uppercase ( ) ;
@@ -155,7 +155,7 @@ impl Cfg {
155155 "on"
156156 } ;
157157
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 ) ) ;
159159 if self . should_append_only_to_description ( ) {
160160 msg. push_str ( " only" ) ;
161161 }
@@ -265,7 +265,9 @@ impl ops::BitOr for Cfg {
265265 }
266266}
267267
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 ) ;
269271
270272fn write_with_opt_paren < T : fmt:: Display > (
271273 fmt : & mut fmt:: Formatter ,
@@ -295,12 +297,12 @@ impl<'a> fmt::Display for Html<'a> {
295297 } ;
296298 for ( i, sub_cfg) in sub_cfgs. iter ( ) . enumerate ( ) {
297299 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 ) ) ?;
299301 }
300302 Ok ( ( ) )
301303 }
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 ) ) ,
304306 } ,
305307
306308 Cfg :: Any ( ref sub_cfgs) => {
@@ -313,7 +315,7 @@ impl<'a> fmt::Display for Html<'a> {
313315 if i != 0 {
314316 fmt. write_str ( separator) ?;
315317 }
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 ) ) ?;
317319 }
318320 Ok ( ( ) )
319321 } ,
@@ -323,7 +325,7 @@ impl<'a> fmt::Display for Html<'a> {
323325 if i != 0 {
324326 fmt. write_str ( " and " ) ?;
325327 }
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 ) ) ?;
327329 }
328330 Ok ( ( ) )
329331 } ,
@@ -390,7 +392,11 @@ impl<'a> fmt::Display for Html<'a> {
390392 ( "target_endian" , Some ( endian) ) => return write ! ( fmt, "{}-endian" , endian) ,
391393 ( "target_pointer_width" , Some ( bits) ) => return write ! ( fmt, "{}-bit" , bits) ,
392394 ( "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+ } ,
394400 _ => "" ,
395401 } ;
396402 if !human_readable. is_empty ( ) {
@@ -405,19 +411,6 @@ impl<'a> fmt::Display for Html<'a> {
405411 }
406412}
407413
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-
421414#[ cfg( test) ]
422415mod test {
423416 use super :: Cfg ;
@@ -740,6 +733,13 @@ mod test {
740733 name_value_cfg( "target_feature" , "sse2" ) . render_short_html( ) ,
741734 "<code>sse2</code>"
742735 ) ;
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+ ) ;
743743 } )
744744 }
745745
@@ -818,6 +818,14 @@ mod test {
818818 name_value_cfg( "target_feature" , "sse2" ) . render_long_html( ) ,
819819 "This is supported with <strong>target feature <code>sse2</code></strong> only."
820820 ) ;
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+ ) ;
821829 } )
822830 }
823831}
0 commit comments