diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2020-10-05 16:24:04 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2020-10-05 19:35:26 +0300 |
| commit | 1444ad7ba1c34685fecf7b0413403151aba51e9d (patch) | |
| tree | fafae164199562565d58d08a13087939cad07527 | |
| parent | 021fcbd90cebe83bb2f0298f2e7001605b5a97d7 (diff) | |
| download | rust-1444ad7ba1c34685fecf7b0413403151aba51e9d.tar.gz rust-1444ad7ba1c34685fecf7b0413403151aba51e9d.zip | |
rustc_target: Further simplify loading of built-in targets
using the fact that it is infallible. JSON roundtrip check on every rustc run is also removed, it's already performed by unit tests.
| -rw-r--r-- | compiler/rustc_driver/src/lib.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_target/src/spec/mod.rs | 51 |
2 files changed, 15 insertions, 39 deletions
diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 3f50c68e3eb..23ed3918c8b 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::<Vec<String>>(); + let mut targets = + rustc_target::spec::TARGETS.iter().copied().collect::<Vec<_>>(); 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 359f5d1fde8..f4f4b45c7ee 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<LinkerFlavor, Vec<String>>; 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<Target, LoadTargetError> { - 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<Item = String> { - TARGETS.iter().filter_map(|t| -> Option<String> { - load_specific(t) - .and(Ok(t.to_string())) - .ok() - }) + pub const TARGETS: &[&str] = &[$($($triple),+),+]; + + fn load_builtin(target: &str) -> Option<Target> { + 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 |
