Skip to content

Commit 6e3561e

Browse files
committed
Rename Type::def_id() to Type::def_id_no_primitives()
The old name was confusing because it's easy to assume that using `def_id()` is fine, but in some situations it's incorrect. In general, `def_id_full()` should be preferred, so `def_id_full()` should have a shorter name. That will happen in the next commit.
1 parent 0853c33 commit 6e3561e

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

src/librustdoc/clean/inline.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,11 @@ crate fn build_impl(
479479
let (merged_attrs, cfg) = merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs);
480480
trace!("merged_attrs={:?}", merged_attrs);
481481

482-
trace!("build_impl: impl {:?} for {:?}", trait_.as_ref().map(|t| t.def_id()), for_.def_id());
482+
trace!(
483+
"build_impl: impl {:?} for {:?}",
484+
trait_.as_ref().map(|t| t.def_id()),
485+
for_.def_id_no_primitives()
486+
);
483487
ret.push(clean::Item::from_def_id_and_attrs_and_parts(
484488
did,
485489
None,

src/librustdoc/clean/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1539,13 +1539,13 @@ impl Type {
15391539
/// [`clean`]: crate::clean
15401540
/// [`clean::Type`]: crate::clean::Type
15411541
// FIXME: get rid of this function and always use `def_id_full`
1542-
crate fn def_id(&self) -> Option<DefId> {
1542+
crate fn def_id_no_primitives(&self) -> Option<DefId> {
15431543
self.inner_def_id(None)
15441544
}
15451545

15461546
/// Use this method to get the [DefId] of a [clean] AST node, including [PrimitiveType]s.
15471547
///
1548-
/// See [`Self::def_id`] for more.
1548+
/// See [`Self::def_id_no_primitives`] for more.
15491549
///
15501550
/// [clean]: crate::clean
15511551
crate fn def_id_full(&self, cache: &Cache) -> Option<DefId> {

src/librustdoc/html/render/cache.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ crate fn get_real_types<'tcx>(
276276
res: &mut FxHashSet<(Type, ItemType)>,
277277
) -> usize {
278278
fn insert(res: &mut FxHashSet<(Type, ItemType)>, tcx: TyCtxt<'_>, ty: Type) -> usize {
279-
if let Some(kind) = ty.def_id().map(|did| tcx.def_kind(did).into()) {
279+
if let Some(kind) = ty.def_id_no_primitives().map(|did| tcx.def_kind(did).into()) {
280280
res.insert((ty, kind));
281281
1
282282
} else if ty.is_primitive() {
@@ -296,7 +296,9 @@ crate fn get_real_types<'tcx>(
296296

297297
if let &Type::Generic(arg_s) = arg {
298298
if let Some(where_pred) = generics.where_predicates.iter().find(|g| match g {
299-
WherePredicate::BoundPredicate { ty, .. } => ty.def_id() == arg.def_id(),
299+
WherePredicate::BoundPredicate { ty, .. } => {
300+
ty.def_id_no_primitives() == arg.def_id_no_primitives()
301+
}
300302
_ => false,
301303
}) {
302304
let bounds = where_pred.get_bounds().unwrap_or_else(|| &[]);
@@ -363,7 +365,8 @@ crate fn get_all_types<'tcx>(
363365
if !args.is_empty() {
364366
all_types.extend(args);
365367
} else {
366-
if let Some(kind) = arg.type_.def_id().map(|did| tcx.def_kind(did).into()) {
368+
if let Some(kind) = arg.type_.def_id_no_primitives().map(|did| tcx.def_kind(did).into())
369+
{
367370
all_types.insert((arg.type_.clone(), kind));
368371
}
369372
}
@@ -374,7 +377,9 @@ crate fn get_all_types<'tcx>(
374377
let mut ret = FxHashSet::default();
375378
get_real_types(generics, &return_type, tcx, 0, &mut ret);
376379
if ret.is_empty() {
377-
if let Some(kind) = return_type.def_id().map(|did| tcx.def_kind(did).into()) {
380+
if let Some(kind) =
381+
return_type.def_id_no_primitives().map(|did| tcx.def_kind(did).into())
382+
{
378383
ret.insert((return_type.clone(), kind));
379384
}
380385
}

src/librustdoc/passes/collect_trait_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl BadImplStripper {
187187
true
188188
} else if let Some(prim) = ty.primitive_type() {
189189
self.prims.contains(&prim)
190-
} else if let Some(did) = ty.def_id() {
190+
} else if let Some(did) = ty.def_id_no_primitives() {
191191
self.keep_impl_with_def_id(did.into())
192192
} else {
193193
false

src/librustdoc/passes/stripper.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl<'a> DocFolder for ImplStripper<'a> {
127127
if imp.trait_.is_none() && imp.items.is_empty() {
128128
return None;
129129
}
130-
if let Some(did) = imp.for_.def_id() {
130+
if let Some(did) = imp.for_.def_id_no_primitives() {
131131
if did.is_local() && !imp.for_.is_assoc_ty() && !self.retained.contains(&did.into())
132132
{
133133
debug!("ImplStripper: impl item for stripped type; removing");
@@ -142,7 +142,7 @@ impl<'a> DocFolder for ImplStripper<'a> {
142142
}
143143
if let Some(generics) = imp.trait_.as_ref().and_then(|t| t.generics()) {
144144
for typaram in generics {
145-
if let Some(did) = typaram.def_id() {
145+
if let Some(did) = typaram.def_id_no_primitives() {
146146
if did.is_local() && !self.retained.contains(&did.into()) {
147147
debug!(
148148
"ImplStripper: stripped item in trait's generics; removing impl"

0 commit comments

Comments
 (0)