about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-02-22 14:58:08 +0100
committerGitHub <noreply@github.com>2019-02-22 14:58:08 +0100
commit555df2bba18bfac212a335c059520d86ac0eb451 (patch)
treee66748ea2d2d2f434bac379c7d706de01c83dede /src
parent575a2096243538868f6ac88dbd99be1b560962fd (diff)
parent103ed0c347062967b8b5fe76a02f945da14aac72 (diff)
downloadrust-555df2bba18bfac212a335c059520d86ac0eb451.tar.gz
rust-555df2bba18bfac212a335c059520d86ac0eb451.zip
Rollup merge of #58601 - gnzlbg:json_error, r=oli-obk
Search for target_triple.json only if builtin target not found

Before this commit, if the builtin target was found, but an error
happened when instantiating it (e.g. validating the target
specification file failed, etc.), then we ignored those errors
and proceeded to try to find a `target_triple.json` file, and if
that failed, reported that as an error.

With this commit, if rustc is supposed to provide the builtin target,
and something fails while instantiating it, that error will
get properly propagated.

r? @oli-obk
Diffstat (limited to 'src')
-rw-r--r--src/librustc_target/spec/mod.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs
index 7cbf24402d7..bef2afc7b62 100644
--- a/src/librustc_target/spec/mod.rs
+++ b/src/librustc_target/spec/mod.rs
@@ -259,6 +259,11 @@ impl ToJson for MergeFunctions {
     }
 }
 
+pub enum LoadTargetError {
+    BuiltinTargetNotFound(String),
+    Other(String),
+}
+
 pub type LinkArgs = BTreeMap<LinkerFlavor, Vec<String>>;
 pub type TargetResult = Result<Target, String>;
 
@@ -269,21 +274,24 @@ macro_rules! supported_targets {
         /// List of supported targets
         const TARGETS: &[&str] = &[$($triple),*];
 
-        fn load_specific(target: &str) -> TargetResult {
+        fn load_specific(target: &str) -> Result<Target, LoadTargetError> {
             match target {
                 $(
                     $triple => {
-                        let mut t = $module::target()?;
+                        let mut t = $module::target()
+                            .map_err(LoadTargetError::Other)?;
                         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())?;
+                        t = Target::from_json(t.to_json())
+                            .map_err(LoadTargetError::Other)?;
                         debug!("Got builtin target: {:?}", t);
                         Ok(t)
                     },
                 )+
-                _ => Err(format!("Unable to find target: {}", target))
+                    _ => Err(LoadTargetError::BuiltinTargetNotFound(
+                        format!("Unable to find target: {}", target)))
             }
         }
 
@@ -1176,8 +1184,10 @@ impl Target {
         match *target_triple {
             TargetTriple::TargetTriple(ref target_triple) => {
                 // check if triple is in list of supported targets
-                if let Ok(t) = load_specific(target_triple) {
-                    return Ok(t)
+                match load_specific(target_triple) {
+                    Ok(t) => return Ok(t),
+                    Err(LoadTargetError::BuiltinTargetNotFound(_)) => (),
+                    Err(LoadTargetError::Other(e)) => return Err(e),
                 }
 
                 // search for a file named `target_triple`.json in RUST_TARGET_PATH