Skip to content

Commit d47dc32

Browse files
committed
diagnostics: don't crash if an injected crate shows up in suggestions
1 parent 0ca70be commit d47dc32

File tree

1 file changed

+4
-1
lines changed
  • compiler/rustc_middle/src/ty

1 file changed

+4
-1
lines changed

compiler/rustc_middle/src/ty/util.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,10 @@ impl<'tcx> TyCtxt<'tcx> {
876876
// | Yes | No | No | !(true && !false) |
877877
// | No | No | Yes | !(false && !false) |
878878
!(self.is_private_dep(key)
879-
&& !self.extern_crate(key.as_def_id()).expect("crate must exist").is_direct())
879+
// If `extern_crate` is `None`, then the crate was injected (e.g., by the allocator).
880+
// Treat that kind of crate as "indirect", since it's an implementation detail of
881+
// the language.
882+
&& !self.extern_crate(key.as_def_id()).map_or(false, |e| e.is_direct()))
880883
}
881884
}
882885

0 commit comments

Comments
 (0)