Skip to content

Commit f93cf66

Browse files
committed
Rename Type::def_id_full() to Type::def_id()
It should be preferred over `def_id_no_primitives()`, so it should have a shorter name. I also put it before `def_id_no_primitives()` so that it shows up first in the docs.
1 parent 6e3561e commit f93cf66

File tree

7 files changed

+28
-31
lines changed

7 files changed

+28
-31
lines changed

src/librustdoc/clean/inline.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ crate fn build_impl(
374374
// Only inline impl if the implementing type is
375375
// reachable in rustdoc generated documentation
376376
if !did.is_local() {
377-
if let Some(did) = for_.def_id_full(&cx.cache) {
377+
if let Some(did) = for_.def_id(&cx.cache) {
378378
if !cx.cache.access_levels.is_public(did) {
379379
return;
380380
}
@@ -462,7 +462,7 @@ crate fn build_impl(
462462
}
463463

464464
while let Some(ty) = stack.pop() {
465-
if let Some(did) = ty.def_id_full(&cx.cache) {
465+
if let Some(did) = ty.def_id(&cx.cache) {
466466
if tcx.get_attrs(did).lists(sym::doc).has_word(sym::hidden) {
467467
return;
468468
}

src/librustdoc/clean/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'tcx> Clean<Type> for ty::ProjectionTy<'tcx> {
385385
let self_type = self.self_ty().clean(cx);
386386
Type::QPath {
387387
name: cx.tcx.associated_item(self.item_def_id).ident.name,
388-
self_def_id: self_type.def_id_full(&cx.cache),
388+
self_def_id: self_type.def_id(&cx.cache),
389389
self_type: box self_type,
390390
trait_,
391391
}
@@ -1887,7 +1887,7 @@ fn clean_impl(impl_: &hir::Impl<'_>, hir_id: hir::HirId, cx: &mut DocContext<'_>
18871887
}
18881888

18891889
let for_ = impl_.self_ty.clean(cx);
1890-
let type_alias = for_.def_id_full(&cx.cache).and_then(|did| match tcx.def_kind(did) {
1890+
let type_alias = for_.def_id(&cx.cache).and_then(|did| match tcx.def_kind(did) {
18911891
DefKind::TyAlias => Some(tcx.type_of(did).clean(cx)),
18921892
_ => None,
18931893
});

src/librustdoc/clean/types.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1529,28 +1529,28 @@ impl Type {
15291529
QPath { ref self_type, .. } => return self_type.inner_def_id(cache),
15301530
Generic(_) | Infer | ImplTrait(_) => return None,
15311531
};
1532-
cache.and_then(|c| Primitive(t).def_id_full(c))
1532+
cache.and_then(|c| Primitive(t).def_id(c))
1533+
}
1534+
1535+
/// Use this method to get the [DefId] of a [clean] AST node, including [PrimitiveType]s.
1536+
///
1537+
/// See [`Self::def_id_no_primitives`] for more.
1538+
///
1539+
/// [clean]: crate::clean
1540+
crate fn def_id(&self, cache: &Cache) -> Option<DefId> {
1541+
self.inner_def_id(Some(cache))
15331542
}
15341543

15351544
/// Use this method to get the [`DefId`] of a [`clean`] AST node.
15361545
/// This will return [`None`] when called on a primitive [`clean::Type`].
1537-
/// Use [`Self::def_id_full`] if you want to include primitives.
1546+
/// Use [`Self::def_id`] if you want to include primitives.
15381547
///
15391548
/// [`clean`]: crate::clean
15401549
/// [`clean::Type`]: crate::clean::Type
1541-
// FIXME: get rid of this function and always use `def_id_full`
1550+
// FIXME: get rid of this function and always use `def_id`
15421551
crate fn def_id_no_primitives(&self) -> Option<DefId> {
15431552
self.inner_def_id(None)
15441553
}
1545-
1546-
/// Use this method to get the [DefId] of a [clean] AST node, including [PrimitiveType]s.
1547-
///
1548-
/// See [`Self::def_id_no_primitives`] for more.
1549-
///
1550-
/// [clean]: crate::clean
1551-
crate fn def_id_full(&self, cache: &Cache) -> Option<DefId> {
1552-
self.inner_def_id(Some(cache))
1553-
}
15541554
}
15551555

15561556
/// A primitive (aka, builtin) type.

src/librustdoc/formats/cache.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
207207
.as_ref()
208208
.map_or(false, |t| self.cache.masked_crates.contains(&t.def_id().krate))
209209
|| i.for_
210-
.def_id_full(self.cache)
210+
.def_id(self.cache)
211211
.map_or(false, |d| self.cache.masked_crates.contains(&d.krate))
212212
{
213213
return None;
@@ -456,7 +456,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
456456

457457
if let Some(generics) = i.trait_.as_ref().and_then(|t| t.generics()) {
458458
for bound in generics {
459-
if let Some(did) = bound.def_id_full(self.cache) {
459+
if let Some(did) = bound.def_id(self.cache) {
460460
dids.insert(did);
461461
}
462462
}

src/librustdoc/html/render/mod.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -1168,8 +1168,8 @@ fn render_deref_methods(
11681168
debug!("Render deref methods for {:#?}, target {:#?}", impl_.inner_impl().for_, target);
11691169
let what =
11701170
AssocItemRender::DerefFor { trait_: deref_type, type_: real_target, deref_mut_: deref_mut };
1171-
if let Some(did) = target.def_id_full(cache) {
1172-
if let Some(type_did) = impl_.inner_impl().for_.def_id_full(cache) {
1171+
if let Some(did) = target.def_id(cache) {
1172+
if let Some(type_did) = impl_.inner_impl().for_.def_id(cache) {
11731173
// `impl Deref<Target = S> for S`
11741174
if did == type_did {
11751175
// Avoid infinite cycles
@@ -1215,7 +1215,7 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool, tcx: TyCtxt<'_>) ->
12151215
fn notable_traits_decl(decl: &clean::FnDecl, cx: &Context<'_>) -> String {
12161216
let mut out = Buffer::html();
12171217

1218-
if let Some(did) = decl.output.as_return().and_then(|t| t.def_id_full(cx.cache())) {
1218+
if let Some(did) = decl.output.as_return().and_then(|t| t.def_id(cx.cache())) {
12191219
if let Some(impls) = cx.cache().impls.get(&did) {
12201220
for i in impls {
12211221
let impl_ = i.inner_impl();
@@ -2058,8 +2058,8 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
20582058
})
20592059
{
20602060
debug!("found target, real_target: {:?} {:?}", target, real_target);
2061-
if let Some(did) = target.def_id_full(c) {
2062-
if let Some(type_did) = impl_.inner_impl().for_.def_id_full(c) {
2061+
if let Some(did) = target.def_id(c) {
2062+
if let Some(type_did) = impl_.inner_impl().for_.def_id(c) {
20632063
// `impl Deref<Target = S> for S`
20642064
if did == type_did {
20652065
// Avoid infinite cycles
@@ -2069,7 +2069,7 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
20692069
}
20702070
let deref_mut = v.iter().any(|i| i.trait_did() == cx.tcx().lang_items().deref_mut_trait());
20712071
let inner_impl = target
2072-
.def_id_full(c)
2072+
.def_id(c)
20732073
.or_else(|| {
20742074
target.primitive_type().and_then(|prim| c.primitive_locations.get(&prim).cloned())
20752075
})
@@ -2232,10 +2232,7 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
22322232
let mut res = implementors
22332233
.iter()
22342234
.filter(|i| {
2235-
i.inner_impl()
2236-
.for_
2237-
.def_id_full(cache)
2238-
.map_or(false, |d| !cache.paths.contains_key(&d))
2235+
i.inner_impl().for_.def_id(cache).map_or(false, |d| !cache.paths.contains_key(&d))
22392236
})
22402237
.filter_map(|i| extract_for_impl_name(&i.impl_item, cx))
22412238
.collect::<Vec<_>>();

src/librustdoc/html/render/print_item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use super::{
2121
render_impl, render_stability_since_raw, write_srclink, AssocItemLink, Context,
2222
ImplRenderingParameters,
2323
};
24-
use crate::clean::{self};
24+
use crate::clean;
2525
use crate::formats::item_type::ItemType;
2626
use crate::formats::{AssocItemRender, Impl, RenderMode};
2727
use crate::html::escape::Escape;
@@ -742,7 +742,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
742742
}
743743

744744
let (local, foreign) = implementors.iter().partition::<Vec<_>, _>(|i| {
745-
i.inner_impl().for_.def_id_full(cache).map_or(true, |d| cache.paths.contains_key(&d))
745+
i.inner_impl().for_.def_id(cache).map_or(true, |d| cache.paths.contains_key(&d))
746746
});
747747

748748
let (mut synthetic, mut concrete): (Vec<&&Impl>, Vec<&&Impl>) =

src/librustdoc/passes/collect_trait_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
7070

7171
if let Some(prim) = target.primitive_type() {
7272
cleaner.prims.insert(prim);
73-
} else if let Some(did) = target.def_id_full(&cx.cache) {
73+
} else if let Some(did) = target.def_id(&cx.cache) {
7474
cleaner.items.insert(did.into());
7575
}
7676
}

0 commit comments

Comments
 (0)