diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 3f50c68e3ebf5..23ed3918c8b20 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -672,7 +672,8 @@ impl RustcDefaultCalls { for req in &sess.opts.prints { match *req { TargetList => { - let mut targets = rustc_target::spec::get_targets().collect::>(); + let mut targets = + rustc_target::spec::TARGETS.iter().copied().collect::>(); targets.sort(); println!("{}", targets.join("\n")); } diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 359f5d1fde891..f4f4b45c7ee83 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -430,11 +430,6 @@ impl fmt::Display for LinkOutputKind { } } -pub enum LoadTargetError { - BuiltinTargetNotFound(String), - Other(String), -} - pub type LinkArgs = BTreeMap>; macro_rules! supported_targets { @@ -442,34 +437,16 @@ macro_rules! supported_targets { $(mod $module;)+ /// List of supported targets - const TARGETS: &[&str] = &[$($($triple),+),+]; - - fn load_specific(target: &str) -> Result { - match target { - $( - $($triple)|+ => { - let mut t = $module::target(); - t.options.is_builtin = true; - - // round-trip through the JSON parser to ensure at - // run-time that the parser works correctly - t = Target::from_json(t.to_json()) - .map_err(LoadTargetError::Other)?; - debug!("got builtin target: {:?}", t); - Ok(t) - }, - )+ - _ => Err(LoadTargetError::BuiltinTargetNotFound( - format!("Unable to find target: {}", target))) - } - } - - pub fn get_targets() -> impl Iterator { - TARGETS.iter().filter_map(|t| -> Option { - load_specific(t) - .and(Ok(t.to_string())) - .ok() - }) + pub const TARGETS: &[&str] = &[$($($triple),+),+]; + + fn load_builtin(target: &str) -> Option { + let mut t = match target { + $( $($triple)|+ => $module::target(), )+ + _ => return None, + }; + t.options.is_builtin = true; + debug!("got builtin target: {:?}", t); + Some(t) } #[cfg(test)] @@ -1529,11 +1506,9 @@ impl Target { match *target_triple { TargetTriple::TargetTriple(ref target_triple) => { - // check if triple is in list of supported targets - match load_specific(target_triple) { - Ok(t) => return Ok(t), - Err(LoadTargetError::BuiltinTargetNotFound(_)) => (), - Err(LoadTargetError::Other(e)) => return Err(e), + // check if triple is in list of built-in targets + if let Some(t) = load_builtin(target_triple) { + return Ok(t); } // search for a file named `target_triple`.json in RUST_TARGET_PATH