@@ -16,6 +16,24 @@ use crate::html::markdown::short_markdown_summary;
1616use crate :: html:: render:: cache:: { get_index_search_type, ExternalLocation } ;
1717use crate :: html:: render:: IndexItem ;
1818
19+ /// A path that is either local, or external. It consists of a fully qualified name,
20+ /// and a type description.
21+ #[ derive( Debug , Clone ) ]
22+ crate enum CachedPath {
23+ Local ( Vec < String > , ItemType ) ,
24+ Extern ( Vec < String > , ItemType ) ,
25+ }
26+
27+ impl CachedPath {
28+ crate fn is_local ( & self ) -> bool {
29+ matches ! ( self , CachedPath :: Local ( ..) )
30+ }
31+
32+ crate fn is_extern ( & self ) -> bool {
33+ matches ! ( self , CachedPath :: Extern ( ..) )
34+ }
35+ }
36+
1937/// This cache is used to store information about the [`clean::Crate`] being
2038/// rendered in order to provide more useful documentation. This contains
2139/// information like all implementors of a trait, all traits a type implements,
@@ -35,16 +53,12 @@ crate struct Cache {
3553 /// found on that implementation.
3654 crate impls : FxHashMap < DefId , Vec < Impl > > ,
3755
38- /// Maintains a mapping of local crate `DefId`s to the fully qualified name
39- /// and "short type description" of that node. This is used when generating
40- /// URLs when a type is being linked to. External paths are not located in
41- /// this map because the `External` type itself has all the information
42- /// necessary.
43- crate paths : FxHashMap < DefId , ( Vec < String > , ItemType ) > ,
44-
45- /// Similar to `paths`, but only holds external paths. This is only used for
46- /// generating explicit hyperlinks to other crates.
47- crate external_paths : FxHashMap < DefId , ( Vec < String > , ItemType ) > ,
56+ /// Maintain a mapping of `DefId`s to the fully qualified name and "shorty type description" of
57+ /// that node. This map contains local and external cached paths that are differentiated using
58+ /// the [`CachedPath`] enum.
59+ ///
60+ /// This was previously known as `extern_paths` and `paths`.
61+ crate paths : FxHashMap < DefId , CachedPath > ,
4862
4963 /// Maps local `DefId`s of exported types to fully qualified paths.
5064 /// Unlike 'paths', this mapping ignores any renames that occur
@@ -156,7 +170,7 @@ impl Cache {
156170 let extern_url = extern_html_root_urls. get ( & * name. as_str ( ) ) . map ( |u| & * * u) ;
157171 let did = DefId { krate : n, index : CRATE_DEF_INDEX } ;
158172 self . extern_locations . insert ( n, e. location ( extern_url, & dst, tcx) ) ;
159- self . external_paths . insert ( did, ( vec ! [ name. to_string( ) ] , ItemType :: Module ) ) ;
173+ self . paths . insert ( did, CachedPath :: Extern ( vec ! [ name. to_string( ) ] , ItemType :: Module ) ) ;
160174 }
161175
162176 // Cache where all known primitives have their documentation located.
@@ -267,15 +281,15 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
267281 // for where the type was defined. On the other
268282 // hand, `paths` always has the right
269283 // information if present.
270- Some ( & (
284+ Some ( CachedPath :: Local (
271285 ref fqp,
272286 ItemType :: Trait
273287 | ItemType :: Struct
274288 | ItemType :: Union
275289 | ItemType :: Enum ,
276290 ) ) => Some ( & fqp[ ..fqp. len ( ) - 1 ] ) ,
277- Some ( .. ) => Some ( & * self . cache . stack ) ,
278- None => None ,
291+ Some ( CachedPath :: Local ( .. ) ) => Some ( & * self . cache . stack ) ,
292+ _ => None ,
279293 } ;
280294 ( ( Some ( * last) , path) , true )
281295 }
@@ -353,15 +367,16 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
353367 {
354368 self . cache . paths . insert (
355369 item. def_id . expect_def_id ( ) ,
356- ( self . cache . stack . clone ( ) , item. type_ ( ) ) ,
370+ CachedPath :: Local ( self . cache . stack . clone ( ) , item. type_ ( ) ) ,
357371 ) ;
358372 }
359373 }
360374 }
361375 clean:: PrimitiveItem ( ..) => {
362- self . cache
363- . paths
364- . insert ( item. def_id . expect_def_id ( ) , ( self . cache . stack . clone ( ) , item. type_ ( ) ) ) ;
376+ self . cache . paths . insert (
377+ item. def_id . expect_def_id ( ) ,
378+ CachedPath :: Local ( self . cache . stack . clone ( ) , item. type_ ( ) ) ,
379+ ) ;
365380 }
366381
367382 clean:: ExternCrateItem { .. }
0 commit comments