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.
This commit is contained in:
Noah Lev 2021-10-21 20:14:56 -07:00
parent 0853c33c3b
commit 6e3561e149
5 changed files with 19 additions and 10 deletions

View File

@ -479,7 +479,11 @@ crate fn build_impl(
let (merged_attrs, cfg) = merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs);
trace!("merged_attrs={:?}", merged_attrs);
trace!("build_impl: impl {:?} for {:?}", trait_.as_ref().map(|t| t.def_id()), for_.def_id());
trace!(
"build_impl: impl {:?} for {:?}",
trait_.as_ref().map(|t| t.def_id()),
for_.def_id_no_primitives()
);
ret.push(clean::Item::from_def_id_and_attrs_and_parts(
did,
None,

View File

@ -1539,13 +1539,13 @@ impl Type {
/// [`clean`]: crate::clean
/// [`clean::Type`]: crate::clean::Type
// FIXME: get rid of this function and always use `def_id_full`
crate fn def_id(&self) -> Option<DefId> {
crate fn def_id_no_primitives(&self) -> Option<DefId> {
self.inner_def_id(None)
}
/// Use this method to get the [DefId] of a [clean] AST node, including [PrimitiveType]s.
///
/// See [`Self::def_id`] for more.
/// See [`Self::def_id_no_primitives`] for more.
///
/// [clean]: crate::clean
crate fn def_id_full(&self, cache: &Cache) -> Option<DefId> {

View File

@ -276,7 +276,7 @@ crate fn get_real_types<'tcx>(
res: &mut FxHashSet<(Type, ItemType)>,
) -> usize {
fn insert(res: &mut FxHashSet<(Type, ItemType)>, tcx: TyCtxt<'_>, ty: Type) -> usize {
if let Some(kind) = ty.def_id().map(|did| tcx.def_kind(did).into()) {
if let Some(kind) = ty.def_id_no_primitives().map(|did| tcx.def_kind(did).into()) {
res.insert((ty, kind));
1
} else if ty.is_primitive() {
@ -296,7 +296,9 @@ crate fn get_real_types<'tcx>(
if let &Type::Generic(arg_s) = arg {
if let Some(where_pred) = generics.where_predicates.iter().find(|g| match g {
WherePredicate::BoundPredicate { ty, .. } => ty.def_id() == arg.def_id(),
WherePredicate::BoundPredicate { ty, .. } => {
ty.def_id_no_primitives() == arg.def_id_no_primitives()
}
_ => false,
}) {
let bounds = where_pred.get_bounds().unwrap_or_else(|| &[]);
@ -363,7 +365,8 @@ crate fn get_all_types<'tcx>(
if !args.is_empty() {
all_types.extend(args);
} else {
if let Some(kind) = arg.type_.def_id().map(|did| tcx.def_kind(did).into()) {
if let Some(kind) = arg.type_.def_id_no_primitives().map(|did| tcx.def_kind(did).into())
{
all_types.insert((arg.type_.clone(), kind));
}
}
@ -374,7 +377,9 @@ crate fn get_all_types<'tcx>(
let mut ret = FxHashSet::default();
get_real_types(generics, &return_type, tcx, 0, &mut ret);
if ret.is_empty() {
if let Some(kind) = return_type.def_id().map(|did| tcx.def_kind(did).into()) {
if let Some(kind) =
return_type.def_id_no_primitives().map(|did| tcx.def_kind(did).into())
{
ret.insert((return_type.clone(), kind));
}
}

View File

@ -187,7 +187,7 @@ impl BadImplStripper {
true
} else if let Some(prim) = ty.primitive_type() {
self.prims.contains(&prim)
} else if let Some(did) = ty.def_id() {
} else if let Some(did) = ty.def_id_no_primitives() {
self.keep_impl_with_def_id(did.into())
} else {
false

View File

@ -127,7 +127,7 @@ impl<'a> DocFolder for ImplStripper<'a> {
if imp.trait_.is_none() && imp.items.is_empty() {
return None;
}
if let Some(did) = imp.for_.def_id() {
if let Some(did) = imp.for_.def_id_no_primitives() {
if did.is_local() && !imp.for_.is_assoc_ty() && !self.retained.contains(&did.into())
{
debug!("ImplStripper: impl item for stripped type; removing");
@ -142,7 +142,7 @@ impl<'a> DocFolder for ImplStripper<'a> {
}
if let Some(generics) = imp.trait_.as_ref().and_then(|t| t.generics()) {
for typaram in generics {
if let Some(did) = typaram.def_id() {
if let Some(did) = typaram.def_id_no_primitives() {
if did.is_local() && !self.retained.contains(&did.into()) {
debug!(
"ImplStripper: stripped item in trait's generics; removing impl"