@@ -958,7 +958,7 @@ impl GenericBound {
958958 crate fn is_sized_bound ( & self , cx : & DocContext < ' _ > ) -> bool {
959959 use rustc_hir:: TraitBoundModifier as TBM ;
960960 if let GenericBound :: TraitBound ( PolyTrait { ref trait_, .. } , TBM :: None ) = * self {
961- if trait_. def_id ( & cx . cache ) == cx. tcx . lang_items ( ) . sized_trait ( ) {
961+ if trait_. def_id ( ) == cx. tcx . lang_items ( ) . sized_trait ( ) {
962962 return true ;
963963 }
964964 }
@@ -1171,9 +1171,16 @@ crate enum FnRetTy {
11711171}
11721172
11731173impl GetDefId for FnRetTy {
1174- fn def_id ( & self , cache : & Cache ) -> Option < DefId > {
1174+ fn def_id ( & self ) -> Option < DefId > {
11751175 match * self {
1176- Return ( ref ty) => ty. def_id ( cache) ,
1176+ Return ( ref ty) => ty. def_id ( ) ,
1177+ DefaultReturn => None ,
1178+ }
1179+ }
1180+
1181+ fn def_id_full ( & self , cache : & Cache ) -> Option < DefId > {
1182+ match * self {
1183+ Return ( ref ty) => ty. def_id_full ( cache) ,
11771184 DefaultReturn => None ,
11781185 }
11791186 }
@@ -1299,12 +1306,20 @@ crate enum TypeKind {
12991306}
13001307
13011308crate trait GetDefId {
1302- fn def_id ( & self , cache : & Cache ) -> Option < DefId > ;
1309+ /// Doesn't retrieve primitive types `DefId`. Use `def_id_full` if you want it.
1310+ fn def_id ( & self ) -> Option < DefId > ;
1311+ /// Retrieves all types' `DefId` (including primitives). If you're not interested about
1312+ /// primitives, use `def_id`.
1313+ fn def_id_full ( & self , cache : & Cache ) -> Option < DefId > ;
13031314}
13041315
13051316impl < T : GetDefId > GetDefId for Option < T > {
1306- fn def_id ( & self , cache : & Cache ) -> Option < DefId > {
1307- self . as_ref ( ) . and_then ( |d| d. def_id ( cache) )
1317+ fn def_id ( & self ) -> Option < DefId > {
1318+ self . as_ref ( ) . and_then ( |d| d. def_id ( ) )
1319+ }
1320+
1321+ fn def_id_full ( & self , cache : & Cache ) -> Option < DefId > {
1322+ self . as_ref ( ) . and_then ( |d| d. def_id_full ( cache) )
13081323 }
13091324}
13101325
@@ -1393,33 +1408,50 @@ impl Type {
13931408 }
13941409}
13951410
1396- impl GetDefId for Type {
1397- fn def_id ( & self , cache : & Cache ) -> Option < DefId > {
1411+ impl Type {
1412+ fn inner_def_id ( & self , cache : Option < & Cache > ) -> Option < DefId > {
1413+ fn inner < T : GetDefId > ( t : & T , cache : Option < & Cache > ) -> Option < DefId > {
1414+ match cache {
1415+ Some ( c) => t. def_id_full ( c) ,
1416+ None => t. def_id ( ) ,
1417+ }
1418+ }
1419+
13981420 match * self {
13991421 ResolvedPath { did, .. } => Some ( did) ,
1400- Primitive ( p) => cache. primitive_locations . get ( & p) . cloned ( ) ,
1422+ Primitive ( p) => cache. and_then ( |c| c . primitive_locations . get ( & p) . cloned ( ) ) ,
14011423 BorrowedRef { type_ : box Generic ( ..) , .. } => {
1402- Primitive ( PrimitiveType :: Reference ) . def_id ( cache)
1424+ inner ( & Primitive ( PrimitiveType :: Reference ) , cache)
14031425 }
1404- BorrowedRef { ref type_, .. } => type_ . def_id ( cache) ,
1426+ BorrowedRef { ref type_, .. } => inner ( & * * type_ , cache) ,
14051427 Tuple ( ref tys) => {
14061428 if tys. is_empty ( ) {
1407- Primitive ( PrimitiveType :: Unit ) . def_id ( cache)
1429+ inner ( & Primitive ( PrimitiveType :: Unit ) , cache)
14081430 } else {
1409- Primitive ( PrimitiveType :: Tuple ) . def_id ( cache)
1431+ inner ( & Primitive ( PrimitiveType :: Tuple ) , cache)
14101432 }
14111433 }
1412- BareFunction ( ..) => Primitive ( PrimitiveType :: Fn ) . def_id ( cache) ,
1413- Never => Primitive ( PrimitiveType :: Never ) . def_id ( cache) ,
1414- Slice ( ..) => Primitive ( PrimitiveType :: Slice ) . def_id ( cache) ,
1415- Array ( ..) => Primitive ( PrimitiveType :: Array ) . def_id ( cache) ,
1416- RawPointer ( ..) => Primitive ( PrimitiveType :: RawPointer ) . def_id ( cache) ,
1417- QPath { ref self_type, .. } => self_type . def_id ( cache) ,
1434+ BareFunction ( ..) => inner ( & Primitive ( PrimitiveType :: Fn ) , cache) ,
1435+ Never => inner ( & Primitive ( PrimitiveType :: Never ) , cache) ,
1436+ Slice ( ..) => inner ( & Primitive ( PrimitiveType :: Slice ) , cache) ,
1437+ Array ( ..) => inner ( & Primitive ( PrimitiveType :: Array ) , cache) ,
1438+ RawPointer ( ..) => inner ( & Primitive ( PrimitiveType :: RawPointer ) , cache) ,
1439+ QPath { ref self_type, .. } => inner ( & * * self_type , cache) ,
14181440 _ => None ,
14191441 }
14201442 }
14211443}
14221444
1445+ impl GetDefId for Type {
1446+ fn def_id ( & self ) -> Option < DefId > {
1447+ self . inner_def_id ( None )
1448+ }
1449+
1450+ fn def_id_full ( & self , cache : & Cache ) -> Option < DefId > {
1451+ self . inner_def_id ( Some ( cache) )
1452+ }
1453+ }
1454+
14231455impl PrimitiveType {
14241456 crate fn from_hir ( prim : hir:: PrimTy ) -> PrimitiveType {
14251457 match prim {
@@ -1814,8 +1846,12 @@ crate struct Typedef {
18141846}
18151847
18161848impl GetDefId for Typedef {
1817- fn def_id ( & self , cache : & Cache ) -> Option < DefId > {
1818- self . type_ . def_id ( cache)
1849+ fn def_id ( & self ) -> Option < DefId > {
1850+ self . type_ . def_id ( )
1851+ }
1852+
1853+ fn def_id_full ( & self , cache : & Cache ) -> Option < DefId > {
1854+ self . type_ . def_id_full ( cache)
18191855 }
18201856}
18211857
0 commit comments