@@ -37,7 +37,7 @@ use crate::clean::inline;
3737use  crate :: clean:: types:: Type :: { QPath ,  ResolvedPath } ; 
3838use  crate :: clean:: Clean ; 
3939use  crate :: core:: DocContext ; 
40- use  crate :: formats:: cache:: cache ; 
40+ use  crate :: formats:: cache:: Cache ; 
4141use  crate :: formats:: item_type:: ItemType ; 
4242use  crate :: html:: render:: cache:: ExternalLocation ; 
4343
@@ -169,8 +169,8 @@ impl Item {
169169        self . attrs . collapsed_doc_value ( ) 
170170    } 
171171
172-     crate  fn  links ( & self )  -> Vec < RenderedLink >  { 
173-         self . attrs . links ( & self . def_id . krate ) 
172+     crate  fn  links ( & self ,   cache :   & Cache )  -> Vec < RenderedLink >  { 
173+         self . attrs . links ( & self . def_id . krate ,  cache ) 
174174    } 
175175
176176    crate  fn  is_crate ( & self )  -> bool  { 
@@ -826,7 +826,7 @@ impl Attributes {
826826    /// Gets links as a vector 
827827/// 
828828/// Cache must be populated before call 
829- crate  fn  links ( & self ,  krate :  & CrateNum )  -> Vec < RenderedLink >  { 
829+ crate  fn  links ( & self ,  krate :  & CrateNum ,   cache :   & Cache )  -> Vec < RenderedLink >  { 
830830        use  crate :: html:: format:: href; 
831831        use  crate :: html:: render:: CURRENT_DEPTH ; 
832832
@@ -835,7 +835,7 @@ impl Attributes {
835835            . filter_map ( |ItemLink  {  link :  s,  link_text,  did,  fragment } | { 
836836                match  * did { 
837837                    Some ( did)  => { 
838-                         if  let  Some ( ( mut  href,  ..) )  = href ( did)  { 
838+                         if  let  Some ( ( mut  href,  ..) )  = href ( did,  cache )  { 
839839                            if  let  Some ( ref  fragment)  = * fragment { 
840840                                href. push ( '#' ) ; 
841841                                href. push_str ( fragment) ; 
@@ -851,7 +851,6 @@ impl Attributes {
851851                    } 
852852                    None  => { 
853853                        if  let  Some ( ref  fragment)  = * fragment { 
854-                             let  cache = cache ( ) ; 
855854                            let  url = match  cache. extern_locations . get ( krate)  { 
856855                                Some ( & ( _,  _,  ExternalLocation :: Local ) )  => { 
857856                                    let  depth = CURRENT_DEPTH . with ( |l| l. get ( ) ) ; 
@@ -1177,6 +1176,13 @@ impl GetDefId for FnRetTy {
11771176            DefaultReturn  => None , 
11781177        } 
11791178    } 
1179+ 
1180+     fn  def_id_full ( & self ,  cache :  & Cache )  -> Option < DefId >  { 
1181+         match  * self  { 
1182+             Return ( ref  ty)  => ty. def_id_full ( cache) , 
1183+             DefaultReturn  => None , 
1184+         } 
1185+     } 
11801186} 
11811187
11821188#[ derive( Clone ,  Debug ) ]  
@@ -1299,13 +1305,31 @@ crate enum TypeKind {
12991305} 
13001306
13011307crate  trait  GetDefId  { 
1308+     /// Use this method to get the [`DefId`] of a [`clean`] AST node. 
1309+ /// This will return [`None`] when called on a primitive [`clean::Type`]. 
1310+ /// Use [`Self::def_id_full`] if you want to include primitives. 
1311+ /// 
1312+ /// [`clean`]: crate::clean 
1313+ /// [`clean::Type`]: crate::clean::Type 
1314+ // FIXME: get rid of this function and always use `def_id_full` 
13021315    fn  def_id ( & self )  -> Option < DefId > ; 
1316+ 
1317+     /// Use this method to get the [DefId] of a [clean] AST node, including [PrimitiveType]s. 
1318+ /// 
1319+ /// See [`Self::def_id`] for more. 
1320+ /// 
1321+ /// [clean]: crate::clean 
1322+ fn  def_id_full ( & self ,  cache :  & Cache )  -> Option < DefId > ; 
13031323} 
13041324
13051325impl < T :  GetDefId >  GetDefId  for  Option < T >  { 
13061326    fn  def_id ( & self )  -> Option < DefId >  { 
13071327        self . as_ref ( ) . and_then ( |d| d. def_id ( ) ) 
13081328    } 
1329+ 
1330+     fn  def_id_full ( & self ,  cache :  & Cache )  -> Option < DefId >  { 
1331+         self . as_ref ( ) . and_then ( |d| d. def_id_full ( cache) ) 
1332+     } 
13091333} 
13101334
13111335impl  Type  { 
@@ -1393,30 +1417,40 @@ impl Type {
13931417    } 
13941418} 
13951419
1396- impl  GetDefId  for  Type  { 
1397-     fn  def_id ( & self )  -> Option < DefId >  { 
1398-         match  * self  { 
1399-             ResolvedPath  {  did,  .. }  => Some ( did) , 
1400-             Primitive ( p)  => cache ( ) . primitive_locations . get ( & p) . cloned ( ) , 
1401-             BorrowedRef  {  type_ :  box Generic ( ..) ,  .. }  => { 
1402-                 Primitive ( PrimitiveType :: Reference ) . def_id ( ) 
1403-             } 
1404-             BorrowedRef  {  ref  type_,  .. }  => type_. def_id ( ) , 
1420+ impl  Type  { 
1421+     fn  inner_def_id ( & self ,  cache :  Option < & Cache > )  -> Option < DefId >  { 
1422+         let  t:  PrimitiveType  = match  * self  { 
1423+             ResolvedPath  {  did,  .. }  => return  Some ( did) , 
1424+             Primitive ( p)  => return  cache. and_then ( |c| c. primitive_locations . get ( & p) . cloned ( ) ) , 
1425+             BorrowedRef  {  type_ :  box Generic ( ..) ,  .. }  => PrimitiveType :: Reference , 
1426+             BorrowedRef  {  ref  type_,  .. }  => return  type_. inner_def_id ( cache) , 
14051427            Tuple ( ref  tys)  => { 
14061428                if  tys. is_empty ( )  { 
1407-                     Primitive ( PrimitiveType :: Unit ) . def_id ( ) 
1429+                     PrimitiveType :: Unit 
14081430                }  else  { 
1409-                     Primitive ( PrimitiveType :: Tuple ) . def_id ( ) 
1431+                     PrimitiveType :: Tuple 
14101432                } 
14111433            } 
1412-             BareFunction ( ..)  => Primitive ( PrimitiveType :: Fn ) . def_id ( ) , 
1413-             Never  => Primitive ( PrimitiveType :: Never ) . def_id ( ) , 
1414-             Slice ( ..)  => Primitive ( PrimitiveType :: Slice ) . def_id ( ) , 
1415-             Array ( ..)  => Primitive ( PrimitiveType :: Array ) . def_id ( ) , 
1416-             RawPointer ( ..)  => Primitive ( PrimitiveType :: RawPointer ) . def_id ( ) , 
1417-             QPath  {  ref  self_type,  .. }  => self_type. def_id ( ) , 
1418-             _ => None , 
1419-         } 
1434+             BareFunction ( ..)  => PrimitiveType :: Fn , 
1435+             Never  => PrimitiveType :: Never , 
1436+             Slice ( ..)  => PrimitiveType :: Slice , 
1437+             Array ( ..)  => PrimitiveType :: Array , 
1438+             RawPointer ( ..)  => PrimitiveType :: RawPointer , 
1439+             QPath  {  ref  self_type,  .. }  => return  self_type. inner_def_id ( cache) , 
1440+             // FIXME: remove this wildcard 
1441+             _ => return  None , 
1442+         } ; 
1443+         cache. and_then ( |c| Primitive ( t) . def_id_full ( c) ) 
1444+     } 
1445+ } 
1446+ 
1447+ impl  GetDefId  for  Type  { 
1448+     fn  def_id ( & self )  -> Option < DefId >  { 
1449+         self . inner_def_id ( None ) 
1450+     } 
1451+ 
1452+     fn  def_id_full ( & self ,  cache :  & Cache )  -> Option < DefId >  { 
1453+         self . inner_def_id ( Some ( cache) ) 
14201454    } 
14211455} 
14221456
@@ -1817,6 +1851,10 @@ impl GetDefId for Typedef {
18171851    fn  def_id ( & self )  -> Option < DefId >  { 
18181852        self . type_ . def_id ( ) 
18191853    } 
1854+ 
1855+     fn  def_id_full ( & self ,  cache :  & Cache )  -> Option < DefId >  { 
1856+         self . type_ . def_id_full ( cache) 
1857+     } 
18201858} 
18211859
18221860#[ derive( Clone ,  Debug ) ]  
0 commit comments