1
Fork 0

Use def_id_full() where easily possible

In general, it should be preferred over `Type::def_id()`. See each
method's docs for more.
This commit is contained in:
Noah Lev 2021-10-21 20:12:20 -07:00
parent bf0cc90050
commit 0853c33c3b
4 changed files with 9 additions and 7 deletions

View file

@ -374,7 +374,7 @@ crate fn build_impl(
// Only inline impl if the implementing type is
// reachable in rustdoc generated documentation
if !did.is_local() {
if let Some(did) = for_.def_id() {
if let Some(did) = for_.def_id_full(&cx.cache) {
if !cx.cache.access_levels.is_public(did) {
return;
}
@ -462,7 +462,7 @@ crate fn build_impl(
}
while let Some(ty) = stack.pop() {
if let Some(did) = ty.def_id() {
if let Some(did) = ty.def_id_full(&cx.cache) {
if tcx.get_attrs(did).lists(sym::doc).has_word(sym::hidden) {
return;
}

View file

@ -385,7 +385,7 @@ impl<'tcx> Clean<Type> for ty::ProjectionTy<'tcx> {
let self_type = self.self_ty().clean(cx);
Type::QPath {
name: cx.tcx.associated_item(self.item_def_id).ident.name,
self_def_id: self_type.def_id(),
self_def_id: self_type.def_id_full(&cx.cache),
self_type: box self_type,
trait_,
}
@ -1887,7 +1887,7 @@ fn clean_impl(impl_: &hir::Impl<'_>, hir_id: hir::HirId, cx: &mut DocContext<'_>
}
let for_ = impl_.self_ty.clean(cx);
let type_alias = for_.def_id().and_then(|did| match tcx.def_kind(did) {
let type_alias = for_.def_id_full(&cx.cache).and_then(|did| match tcx.def_kind(did) {
DefKind::TyAlias => Some(tcx.type_of(did).clean(cx)),
_ => None,
});

View file

@ -206,7 +206,9 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|| i.trait_
.as_ref()
.map_or(false, |t| self.cache.masked_crates.contains(&t.def_id().krate))
|| i.for_.def_id().map_or(false, |d| self.cache.masked_crates.contains(&d.krate))
|| i.for_
.def_id_full(self.cache)
.map_or(false, |d| self.cache.masked_crates.contains(&d.krate))
{
return None;
}
@ -454,7 +456,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
if let Some(generics) = i.trait_.as_ref().and_then(|t| t.generics()) {
for bound in generics {
if let Some(did) = bound.def_id() {
if let Some(did) = bound.def_id_full(self.cache) {
dids.insert(did);
}
}

View file

@ -70,7 +70,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
if let Some(prim) = target.primitive_type() {
cleaner.prims.insert(prim);
} else if let Some(did) = target.def_id() {
} else if let Some(did) = target.def_id_full(&cx.cache) {
cleaner.items.insert(did.into());
}
}