diff options
| author | Michael Howell <michael@notriddle.com> | 2023-05-01 12:05:20 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2023-05-25 08:14:33 -0700 |
| commit | 674a3d5c1c898156d7e4bba686593797f44d812a (patch) | |
| tree | 50deb8a27540e47ddb5b5f6dd9c04285891924ba /compiler/rustc_middle/src | |
| parent | e36020cdb33a1c56ec4ff8c9fbb0bf331ade428a (diff) | |
| download | rust-674a3d5c1c898156d7e4bba686593797f44d812a.tar.gz rust-674a3d5c1c898156d7e4bba686593797f44d812a.zip | |
diagnostics: exclude indirect private deps from trait impl suggest
Fixes #88696
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/ty/util.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index ba05135638e..8bf60c40b85 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -15,7 +15,7 @@ use rustc_data_structures::stable_hasher::{Hash64, HashStable, StableHasher}; use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; -use rustc_hir::def_id::{DefId, LocalDefId}; +use rustc_hir::def_id::{CrateNum, DefId, LocalDefId}; use rustc_index::bit_set::GrowableBitSet; use rustc_index::{Idx, IndexVec}; use rustc_macros::HashStable; @@ -857,6 +857,27 @@ impl<'tcx> TyCtxt<'tcx> { _ => def_kind.article(), } } + + /// Return `true` if the supplied `CrateNum` is "user-visible," meaning either a [public] + /// dependency, or a [direct] private dependency. This is used to decide whether the crate can + /// be shown in `impl` suggestions. + /// + /// # Panics + /// + /// This function assumes `key` exists. + /// + /// [public]: TyCtxt::is_private_dep + /// [direct]: rustc_session::cstore::ExternCrate::is_direct + pub fn is_user_visible_dep(self, key: CrateNum) -> bool { + // | Private | Direct | Visible | | + // |---------|--------|---------|--------------------| + // | Yes | Yes | Yes | !(true && !true) | + // | No | Yes | Yes | !(false && !true) | + // | 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()) + } } struct OpaqueTypeExpander<'tcx> { |
