@@ -430,46 +430,23 @@ impl fmt::Display for LinkOutputKind {
430
430
}
431
431
}
432
432
433
- pub enum LoadTargetError {
434
- BuiltinTargetNotFound ( String ) ,
435
- Other ( String ) ,
436
- }
437
-
438
433
pub type LinkArgs = BTreeMap < LinkerFlavor , Vec < String > > ;
439
434
440
435
macro_rules! supported_targets {
441
436
( $( ( $( $triple: literal, ) + $module: ident ) , ) + ) => {
442
437
$( mod $module; ) +
443
438
444
439
/// List of supported targets
445
- const TARGETS : & [ & str ] = & [ $( $( $triple) ,+) ,+] ;
446
-
447
- fn load_specific( target: & str ) -> Result <Target , LoadTargetError > {
448
- match target {
449
- $(
450
- $( $triple) |+ => {
451
- let mut t = $module:: target( ) ;
452
- t. options. is_builtin = true ;
453
-
454
- // round-trip through the JSON parser to ensure at
455
- // run-time that the parser works correctly
456
- t = Target :: from_json( t. to_json( ) )
457
- . map_err( LoadTargetError :: Other ) ?;
458
- debug!( "got builtin target: {:?}" , t) ;
459
- Ok ( t)
460
- } ,
461
- ) +
462
- _ => Err ( LoadTargetError :: BuiltinTargetNotFound (
463
- format!( "Unable to find target: {}" , target) ) )
464
- }
465
- }
466
-
467
- pub fn get_targets( ) -> impl Iterator <Item = String > {
468
- TARGETS . iter( ) . filter_map( |t| -> Option <String > {
469
- load_specific( t)
470
- . and( Ok ( t. to_string( ) ) )
471
- . ok( )
472
- } )
440
+ pub const TARGETS : & [ & str ] = & [ $( $( $triple) ,+) ,+] ;
441
+
442
+ fn load_builtin( target: & str ) -> Option <Target > {
443
+ let mut t = match target {
444
+ $( $( $triple) |+ => $module:: target( ) , ) +
445
+ _ => return None ,
446
+ } ;
447
+ t. options. is_builtin = true ;
448
+ debug!( "got builtin target: {:?}" , t) ;
449
+ Some ( t)
473
450
}
474
451
475
452
#[ cfg( test) ]
@@ -1529,11 +1506,9 @@ impl Target {
1529
1506
1530
1507
match * target_triple {
1531
1508
TargetTriple :: TargetTriple ( ref target_triple) => {
1532
- // check if triple is in list of supported targets
1533
- match load_specific ( target_triple) {
1534
- Ok ( t) => return Ok ( t) ,
1535
- Err ( LoadTargetError :: BuiltinTargetNotFound ( _) ) => ( ) ,
1536
- Err ( LoadTargetError :: Other ( e) ) => return Err ( e) ,
1509
+ // check if triple is in list of built-in targets
1510
+ if let Some ( t) = load_builtin ( target_triple) {
1511
+ return Ok ( t) ;
1537
1512
}
1538
1513
1539
1514
// search for a file named `target_triple`.json in RUST_TARGET_PATH
0 commit comments