@@ -292,30 +292,33 @@ fn llvm_target_features(tm: &llvm::TargetMachine) -> Vec<(&str, &str)> {
292
292
}
293
293
294
294
fn print_target_features ( sess : & Session , tm : & llvm:: TargetMachine ) {
295
- let mut target_features = llvm_target_features ( tm) ;
295
+ let mut llvm_target_features = llvm_target_features ( tm) ;
296
+ let mut known_llvm_target_features = FxHashSet :: < & ' static str > :: default ( ) ;
296
297
let mut rustc_target_features = supported_target_features ( sess)
297
298
. iter ( )
298
- . filter_map ( |( feature, _gate) | {
299
- for llvm_feature in to_llvm_features ( sess, * feature) {
299
+ . map ( |( feature, _gate) | {
300
+ let desc = if let Some ( llvm_feature) = to_llvm_features ( sess, * feature) . first ( ) {
300
301
// LLVM asserts that these are sorted. LLVM and Rust both use byte comparison for these strings.
301
- match target_features. binary_search_by_key ( & llvm_feature, |( f, _d) | f) . ok ( ) . map (
302
- |index| {
303
- let ( _f, desc) = target_features. remove ( index) ;
304
- ( * feature, desc)
305
- } ,
306
- ) {
307
- Some ( v) => return Some ( v) ,
308
- None => { }
302
+ match llvm_target_features. binary_search_by_key ( & llvm_feature, |( f, _d) | f) . ok ( ) {
303
+ Some ( index) => {
304
+ known_llvm_target_features. insert ( llvm_feature) ;
305
+ llvm_target_features[ index] . 1
306
+ }
307
+ None => "" ,
309
308
}
310
- }
311
- None
309
+ } else {
310
+ ""
311
+ } ;
312
+ ( * feature, desc)
312
313
} )
313
314
. collect :: < Vec < _ > > ( ) ;
314
315
rustc_target_features. extend_from_slice ( & [ (
315
316
"crt-static" ,
316
317
"Enables C Run-time Libraries to be statically linked" ,
317
318
) ] ) ;
318
- let max_feature_len = target_features
319
+ llvm_target_features. retain ( |( f, _d) | !known_llvm_target_features. contains ( f) ) ;
320
+
321
+ let max_feature_len = llvm_target_features
319
322
. iter ( )
320
323
. chain ( rustc_target_features. iter ( ) )
321
324
. map ( |( feature, _desc) | feature. len ( ) )
@@ -327,10 +330,10 @@ fn print_target_features(sess: &Session, tm: &llvm::TargetMachine) {
327
330
println ! ( " {1:0$} - {2}." , max_feature_len, feature, desc) ;
328
331
}
329
332
println ! ( "\n Code-generation features supported by LLVM for this target:" ) ;
330
- for ( feature, desc) in & target_features {
333
+ for ( feature, desc) in & llvm_target_features {
331
334
println ! ( " {1:0$} - {2}." , max_feature_len, feature, desc) ;
332
335
}
333
- if target_features . is_empty ( ) {
336
+ if llvm_target_features . is_empty ( ) {
334
337
println ! ( " Target features listing is not supported by this LLVM version." ) ;
335
338
}
336
339
println ! ( "\n Use +feature to enable a feature, or -feature to disable it." ) ;
0 commit comments