@@ -16,6 +16,24 @@ use crate::html::markdown::short_markdown_summary;
16
16
use crate :: html:: render:: cache:: { get_index_search_type, ExternalLocation } ;
17
17
use crate :: html:: render:: IndexItem ;
18
18
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
+
19
37
/// This cache is used to store information about the [`clean::Crate`] being
20
38
/// rendered in order to provide more useful documentation. This contains
21
39
/// information like all implementors of a trait, all traits a type implements,
@@ -35,16 +53,12 @@ crate struct Cache {
35
53
/// found on that implementation.
36
54
crate impls : FxHashMap < DefId , Vec < Impl > > ,
37
55
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 > ,
48
62
49
63
/// Maps local `DefId`s of exported types to fully qualified paths.
50
64
/// Unlike 'paths', this mapping ignores any renames that occur
@@ -156,7 +170,7 @@ impl Cache {
156
170
let extern_url = extern_html_root_urls. get ( & * name. as_str ( ) ) . map ( |u| & * * u) ;
157
171
let did = DefId { krate : n, index : CRATE_DEF_INDEX } ;
158
172
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 ) ) ;
160
174
}
161
175
162
176
// Cache where all known primitives have their documentation located.
@@ -267,15 +281,15 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
267
281
// for where the type was defined. On the other
268
282
// hand, `paths` always has the right
269
283
// information if present.
270
- Some ( & (
284
+ Some ( CachedPath :: Local (
271
285
ref fqp,
272
286
ItemType :: Trait
273
287
| ItemType :: Struct
274
288
| ItemType :: Union
275
289
| ItemType :: Enum ,
276
290
) ) => Some ( & fqp[ ..fqp. len ( ) - 1 ] ) ,
277
- Some ( .. ) => Some ( & * self . cache . stack ) ,
278
- None => None ,
291
+ Some ( CachedPath :: Local ( .. ) ) => Some ( & * self . cache . stack ) ,
292
+ _ => None ,
279
293
} ;
280
294
( ( Some ( * last) , path) , true )
281
295
}
@@ -353,15 +367,16 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
353
367
{
354
368
self . cache . paths . insert (
355
369
item. def_id . expect_def_id ( ) ,
356
- ( self . cache . stack . clone ( ) , item. type_ ( ) ) ,
370
+ CachedPath :: Local ( self . cache . stack . clone ( ) , item. type_ ( ) ) ,
357
371
) ;
358
372
}
359
373
}
360
374
}
361
375
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
+ ) ;
365
380
}
366
381
367
382
clean:: ExternCrateItem { .. }
0 commit comments