diagnostics: don't crash if an injected crate shows up in suggestions

This commit is contained in:
Michael Howell
2023-05-08 13:41:39 -07:00
parent 0ca70be11b
commit d47dc326d6
+4 -1
View File
@@ -876,7 +876,10 @@ pub fn is_user_visible_dep(self, key: CrateNum) -> bool {
// | Yes | No | No | !(true && !false) |
// | No | No | Yes | !(false && !false) |
!(self.is_private_dep(key)
&& !self.extern_crate(key.as_def_id()).expect("crate must exist").is_direct())
// If `extern_crate` is `None`, then the crate was injected (e.g., by the allocator).
// Treat that kind of crate as "indirect", since it's an implementation detail of
// the language.
&& !self.extern_crate(key.as_def_id()).map_or(false, |e| e.is_direct()))
}
}