@@ -77,6 +77,9 @@ pub struct CStore {
7777 unused_externs : Vec < Symbol > ,
7878
7979 used_extern_options : FxHashSet < Symbol > ,
80+ /// Whether there was a failure in resolving crate,
81+ /// it's used to suppress some diagnostics that would otherwise too noisey.
82+ has_crate_resolve_with_fail : bool ,
8083}
8184
8285impl std:: fmt:: Debug for CStore {
@@ -328,6 +331,10 @@ impl CStore {
328331 self . has_alloc_error_handler
329332 }
330333
334+ pub fn had_extern_crate_load_failure ( & self ) -> bool {
335+ self . has_crate_resolve_with_fail
336+ }
337+
331338 pub fn report_unused_deps ( & self , tcx : TyCtxt < ' _ > ) {
332339 let json_unused_externs = tcx. sess . opts . json_unused_externs ;
333340
@@ -514,6 +521,7 @@ impl CStore {
514521 resolved_externs : UnordMap :: default ( ) ,
515522 unused_externs : Vec :: new ( ) ,
516523 used_extern_options : Default :: default ( ) ,
524+ has_crate_resolve_with_fail : false ,
517525 }
518526 }
519527
@@ -723,6 +731,13 @@ impl CStore {
723731 }
724732 Err ( err) => {
725733 debug ! ( "failed to resolve crate {} {:?}" , name, dep_kind) ;
734+ // crate maybe injrected with `standard_library_imports::inject`, their span is dummy.
735+ // we ignore compiler-injected prelude/sysroot loads here so they don't suppress
736+ // unrelated diagnostics, such as `unsupported targets for std library` etc,
737+ // these maybe helpful for users to resolve crate loading failure.
738+ if !tcx. sess . dcx ( ) . has_errors ( ) . is_some ( ) && !span. is_dummy ( ) {
739+ self . has_crate_resolve_with_fail = true ;
740+ }
726741 let missing_core = self
727742 . maybe_resolve_crate (
728743 tcx,
0 commit comments