diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 411c8111cc92..3c8ea1a9f43d 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -731,7 +731,11 @@ fn resolve_crate<'tcx>( } Err(err) => { debug!("failed to resolve crate {} {:?}", name, dep_kind); - if !tcx.sess.dcx().has_errors().is_some() { + // crate maybe injrected with `standard_library_imports::inject`, their span is dummy. + // we ignore compiler-injected prelude/sysroot loads here so they don't suppress + // unrelated diagnostics, such as `unsupported targets for std library` etc, + // these maybe helpful for users to resolve crate loading failure. + if !tcx.sess.dcx().has_errors().is_some() && !span.is_dummy() { self.has_crate_resolve_with_fail = true; } let missing_core = self diff --git a/tests/ui/extern-flag/empty-extern-arg.rs b/tests/ui/extern-flag/empty-extern-arg.rs index db97cee91e50..10cc3be71135 100644 --- a/tests/ui/extern-flag/empty-extern-arg.rs +++ b/tests/ui/extern-flag/empty-extern-arg.rs @@ -5,3 +5,6 @@ //@ ignore-emscripten missing eh_catch_typeinfo lang item fn main() {} + +//~? ERROR `#[panic_handler]` function required, but not found +//~? ERROR unwinding panics are not supported without std diff --git a/tests/ui/extern-flag/empty-extern-arg.stderr b/tests/ui/extern-flag/empty-extern-arg.stderr index 3ce92522d419..3e0a0d6cd5f8 100644 --- a/tests/ui/extern-flag/empty-extern-arg.stderr +++ b/tests/ui/extern-flag/empty-extern-arg.stderr @@ -2,5 +2,12 @@ error: extern location for std does not exist: error: cannot resolve a prelude import -error: aborting due to 2 previous errors +error: `#[panic_handler]` function required, but not found + +error: unwinding panics are not supported without std + | + = help: using nightly cargo, use -Zbuild-std with panic="abort" to avoid unwinding + = note: since the core library is usually precompiled with panic="unwind", rebuilding your crate with panic="abort" may not be enough to fix the problem + +error: aborting due to 4 previous errors