Skip to content

Commit 827a181

Browse files
committed
diagnostics: don't crash if an injected crate shows up in suggestions
1 parent d7041de commit 827a181

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,10 @@ impl<'tcx> TyCtxt<'tcx> {
827827
// | Yes | No | No | !(true && !false) |
828828
// | No | No | Yes | !(false && !false) |
829829
!(self.is_private_dep(key)
830-
&& !self.extern_crate(key.as_def_id()).expect("crate must exist").is_direct())
830+
// If `extern_crate` is `None`, then the crate was injected (e.g., by the allocator).
831+
// Treat that kind of crate as "indirect", since it's an implementation detail of
832+
// the language.
833+
&& !self.extern_crate(key.as_def_id()).map_or(false, |e| e.is_direct()))
831834
}
832835
}
833836

0 commit comments

Comments
 (0)