diff options
| author | Michael Howell <michael@notriddle.com> | 2023-05-08 13:41:39 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2023-05-25 08:15:04 -0700 |
| commit | d47dc326d63c6ed9cc2cd7f99596b5f1e051906d (patch) | |
| tree | 082cc18d05b291aec1e9eb5c0523e9928945e40a | |
| parent | 0ca70be11b6b290d5d7d56dbe9ccd832be5a6809 (diff) | |
| download | rust-d47dc326d63c6ed9cc2cd7f99596b5f1e051906d.tar.gz rust-d47dc326d63c6ed9cc2cd7f99596b5f1e051906d.zip | |
diagnostics: don't crash if an injected crate shows up in suggestions
| -rw-r--r-- | compiler/rustc_middle/src/ty/util.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 8bf60c40b85..6704f3eeb2a 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -876,7 +876,10 @@ impl<'tcx> TyCtxt<'tcx> { // | 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())) } } |
