@@ -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 = Html ( self ) . to_string ( ) ;
141
+ let mut msg = ShortHtml ( self ) . 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 ( ) ;
@@ -149,7 +149,13 @@ impl Cfg {
149
149
150
150
/// Renders the configuration for long display, as a long HTML description.
151
151
pub ( crate ) fn render_long_html ( & self ) -> String {
152
- let mut msg = format ! ( "This is supported on <strong>{}</strong>" , Html ( self ) ) ;
152
+ let on = if self . should_use_with_in_description ( ) {
153
+ "with"
154
+ } else {
155
+ "on"
156
+ } ;
157
+
158
+ let mut msg = format ! ( "This is supported {} <strong>{}</strong>" , on, Html ( self ) ) ;
153
159
if self . should_append_only_to_description ( ) {
154
160
msg. push_str ( " only" ) ;
155
161
}
@@ -180,6 +186,13 @@ impl Cfg {
180
186
}
181
187
}
182
188
}
189
+
190
+ fn should_use_with_in_description ( & self ) -> bool {
191
+ match * self {
192
+ Cfg :: Cfg ( ref name, _) if name == & "target_feature" => true ,
193
+ _ => false ,
194
+ }
195
+ }
183
196
}
184
197
185
198
impl ops:: Not for Cfg {
@@ -376,6 +389,8 @@ impl<'a> fmt::Display for Html<'a> {
376
389
} ,
377
390
( "target_endian" , Some ( endian) ) => return write ! ( fmt, "{}-endian" , endian) ,
378
391
( "target_pointer_width" , Some ( bits) ) => return write ! ( fmt, "{}-bit" , bits) ,
392
+ ( "target_feature" , Some ( feat) ) =>
393
+ return write ! ( fmt, "target feature <code>{}</code>" , feat) ,
379
394
_ => "" ,
380
395
} ;
381
396
if !human_readable. is_empty ( ) {
@@ -390,6 +405,19 @@ impl<'a> fmt::Display for Html<'a> {
390
405
}
391
406
}
392
407
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
+
393
421
#[ cfg( test) ]
394
422
mod test {
395
423
use super :: Cfg ;
@@ -824,6 +852,10 @@ mod test {
824
852
) . render_short_html( ) ,
825
853
"(Debug-assertions enabled or Windows) and Unix"
826
854
) ;
855
+ assert_eq ! (
856
+ name_value_cfg( "target_feature" , "sse2" ) . render_short_html( ) ,
857
+ "<code>sse2</code>"
858
+ ) ;
827
859
} )
828
860
}
829
861
@@ -898,6 +930,10 @@ mod test {
898
930
"This is supported on <strong>(debug-assertions enabled or Windows) and Unix\
899
931
</strong> only."
900
932
) ;
933
+ assert_eq ! (
934
+ name_value_cfg( "target_feature" , "sse2" ) . render_long_html( ) ,
935
+ "This is supported with <strong>target feature <code>sse2</code></strong> only."
936
+ ) ;
901
937
} )
902
938
}
903
939
}
0 commit comments