@@ -430,46 +430,23 @@ impl fmt::Display for LinkOutputKind {
430430 }
431431}
432432
433- pub enum LoadTargetError {
434- BuiltinTargetNotFound ( String ) ,
435- Other ( String ) ,
436- }
437-
438433pub type LinkArgs = BTreeMap < LinkerFlavor , Vec < String > > ;
439434
440435macro_rules! supported_targets {
441436 ( $( ( $( $triple: literal, ) + $module: ident ) , ) + ) => {
442437 $( mod $module; ) +
443438
444439 /// 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)
473450 }
474451
475452 #[ cfg( test) ]
@@ -1529,11 +1506,9 @@ impl Target {
15291506
15301507 match * target_triple {
15311508 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) ;
15371512 }
15381513
15391514 // search for a file named `target_triple`.json in RUST_TARGET_PATH
0 commit comments