about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNoah Lev <camelidcamel@gmail.com>2021-10-21 20:14:56 -0700
committerNoah Lev <camelidcamel@gmail.com>2021-10-22 13:07:43 -0700
commit6e3561e149870fc60f27a3035747a0fe14ffd9f5 (patch)
treebef68600d74d789b928674dabe71a96c01222677 /src
parent0853c33c3b489d5bf0045bf306d6555097f595f4 (diff)
downloadrust-6e3561e149870fc60f27a3035747a0fe14ffd9f5.tar.gz
rust-6e3561e149870fc60f27a3035747a0fe14ffd9f5.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/clean/inline.rs6
-rw-r--r--src/librustdoc/clean/types.rs4
-rw-r--r--src/librustdoc/html/render/cache.rs13
-rw-r--r--src/librustdoc/passes/collect_trait_impls.rs2
-rw-r--r--src/librustdoc/passes/stripper.rs4
5 files changed, 19 insertions, 10 deletions
diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs
index 3d5c1fee168..854f332dd99 100644
--- a/src/librustdoc/clean/inline.rs
+++ b/src/librustdoc/clean/inline.rs
@@ -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,
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
index 0395c6a729e..bd3308c1898 100644
--- a/src/librustdoc/clean/types.rs
+++ b/src/librustdoc/clean/types.rs
@@ -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> {
diff --git a/src/librustdoc/html/render/cache.rs b/src/librustdoc/html/render/cache.rs
index 4cc037f933e..20c5d6dfd8a 100644
--- a/src/librustdoc/html/render/cache.rs
+++ b/src/librustdoc/html/render/cache.rs
@@ -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));
                 }
             }
diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs
index f8f5118042f..0b2ee0d12c1 100644
--- a/src/librustdoc/passes/collect_trait_impls.rs
+++ b/src/librustdoc/passes/collect_trait_impls.rs
@@ -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
diff --git a/src/librustdoc/passes/stripper.rs b/src/librustdoc/passes/stripper.rs
index a160e31a450..74a9a2da06d 100644
--- a/src/librustdoc/passes/stripper.rs
+++ b/src/librustdoc/passes/stripper.rs
@@ -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"