Auto merge of #135278 - tgross35:ignore-std-dep-crates, r=SparrowLii
Exclude dependencies of `std` for diagnostics Currently crates in the sysroot can show up in diagnostic suggestions, such as in https://github.com/rust-lang/rust/issues/135232. To prevent this, duplicate `all_traits` into `visible_traits` which only shows traits in non-private crates. Setting `#![feature(rustc_private)]` overrides this and makes items in private crates visible as well, since `rustc_private` enables use of `std`'s private dependencies. This may be reviewed per-commit. Fixes: https://github.com/rust-lang/rust/issues/135232
This commit is contained in:
commit
8c39ce5b4f
11 changed files with 225 additions and 44 deletions
|
@ -2129,6 +2129,8 @@ rustc_queries! {
|
|||
eval_always
|
||||
desc { "calculating the stability index for the local crate" }
|
||||
}
|
||||
/// All available crates in the graph, including those that should not be user-facing
|
||||
/// (such as private crates).
|
||||
query crates(_: ()) -> &'tcx [CrateNum] {
|
||||
eval_always
|
||||
desc { "fetching all foreign CrateNum instances" }
|
||||
|
|
|
@ -2078,12 +2078,23 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
self.limits(()).move_size_limit
|
||||
}
|
||||
|
||||
/// All traits in the crate graph, including those not visible to the user.
|
||||
pub fn all_traits(self) -> impl Iterator<Item = DefId> + 'tcx {
|
||||
iter::once(LOCAL_CRATE)
|
||||
.chain(self.crates(()).iter().copied())
|
||||
.flat_map(move |cnum| self.traits(cnum).iter().copied())
|
||||
}
|
||||
|
||||
/// All traits that are visible within the crate graph (i.e. excluding private dependencies).
|
||||
pub fn visible_traits(self) -> impl Iterator<Item = DefId> + 'tcx {
|
||||
let visible_crates =
|
||||
self.crates(()).iter().copied().filter(move |cnum| self.is_user_visible_dep(*cnum));
|
||||
|
||||
iter::once(LOCAL_CRATE)
|
||||
.chain(visible_crates)
|
||||
.flat_map(move |cnum| self.traits(cnum).iter().copied())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn local_visibility(self, def_id: LocalDefId) -> Visibility {
|
||||
self.visibility(def_id).expect_local()
|
||||
|
|
|
@ -876,6 +876,11 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
/// [public]: TyCtxt::is_private_dep
|
||||
/// [direct]: rustc_session::cstore::ExternCrate::is_direct
|
||||
pub fn is_user_visible_dep(self, key: CrateNum) -> bool {
|
||||
// `#![rustc_private]` overrides defaults to make private dependencies usable.
|
||||
if self.features().enabled(sym::rustc_private) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// | Private | Direct | Visible | |
|
||||
// |---------|--------|---------|--------------------|
|
||||
// | Yes | Yes | Yes | !true || true |
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue