From 66de87ffb230c3d0c0293dd15eb8571a7b66cdf5 Mon Sep 17 00:00:00 2001 From: Robert Vally Date: Thu, 17 Nov 2016 13:59:28 +0800 Subject: [PATCH] Improved error reporting when target sysroot is missing. --- src/librustc_metadata/locator.rs | 7 ++++++- src/test/compile-fail/issue-37131.rs | 18 ++++++++++++++++++ src/tools/compiletest/src/runtest.rs | 14 ++++++++++++-- 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 src/test/compile-fail/issue-37131.rs diff --git a/src/librustc_metadata/locator.rs b/src/librustc_metadata/locator.rs index b6b347fff5f26..b677a63edc064 100644 --- a/src/librustc_metadata/locator.rs +++ b/src/librustc_metadata/locator.rs @@ -217,7 +217,7 @@ use creader::Library; use schema::{METADATA_HEADER, rustc_version}; use rustc::hir::svh::Svh; -use rustc::session::Session; +use rustc::session::{config, Session}; use rustc::session::filesearch::{FileSearch, FileMatches, FileDoesntMatch}; use rustc::session::search_paths::PathKind; use rustc::util::common; @@ -355,6 +355,11 @@ impl<'a> Context<'a> { "can't find crate for `{}`{}", self.ident, add); + + if (self.ident == "std" || self.ident == "core") + && self.triple != config::host_triple() { + err.note(&format!("the `{}` target may not be installed", self.triple)); + } err.span_label(self.span, &format!("can't find crate")); err }; diff --git a/src/test/compile-fail/issue-37131.rs b/src/test/compile-fail/issue-37131.rs new file mode 100644 index 0000000000000..88c6eb7f515c3 --- /dev/null +++ b/src/test/compile-fail/issue-37131.rs @@ -0,0 +1,18 @@ +// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Tests that compiling for a target which is not installed will result in a helpful +// error message. + +// compile-flags: --target=s390x-unknown-linux-gnu +// ignore s390x + +// error-pattern:target may not be installed +fn main() { } diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 4c024434e17c6..3cc14541fcdf2 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1334,8 +1334,18 @@ actual:\n\ // FIXME (#9639): This needs to handle non-utf8 paths let mut args = vec![input_file.to_str().unwrap().to_owned(), "-L".to_owned(), - self.config.build_base.to_str().unwrap().to_owned(), - format!("--target={}", target)]; + self.config.build_base.to_str().unwrap().to_owned()]; + + // Optionally prevent default --target if specified in test compile-flags. + let custom_target = self.props.compile_flags + .iter() + .fold(false, |acc, ref x| acc || x.starts_with("--target")); + + if !custom_target { + args.extend(vec![ + format!("--target={}", target), + ]); + } if let Some(revision) = self.revision { args.extend(vec![