@@ -49,6 +49,10 @@ pub(crate) struct Context<'tcx> {
49
49
/// Current hierarchy of components leading down to what's currently being
50
50
/// rendered
51
51
pub ( crate ) current : Vec < Symbol > ,
52
+ /// Set of visible DefIds in the current module.
53
+ /// This generates optimal link hrefs in the common case when
54
+ /// an entire module is glob-inlined and its children link to each other.
55
+ pub ( crate ) current_module_linkable_items : DefIdMap < ( ItemType , Symbol ) > ,
52
56
/// The current destination folder of where HTML artifacts should be placed.
53
57
/// This changes as the context descends into the module hierarchy.
54
58
pub ( crate ) dst : PathBuf ,
@@ -79,9 +83,9 @@ pub(crate) struct Context<'tcx> {
79
83
80
84
// `Context` is cloned a lot, so we don't want the size to grow unexpectedly.
81
85
#[ cfg( all( not( windows) , target_pointer_width = "64" ) ) ]
82
- rustc_data_structures:: static_assert_size!( Context <' _>, 160 ) ;
86
+ rustc_data_structures:: static_assert_size!( Context <' _>, 192 ) ;
83
87
#[ cfg( all( windows, target_pointer_width = "64" ) ) ]
84
- rustc_data_structures:: static_assert_size!( Context <' _>, 168 ) ;
88
+ rustc_data_structures:: static_assert_size!( Context <' _>, 200 ) ;
85
89
86
90
/// Shared mutable state used in [`Context`] and elsewhere.
87
91
pub ( crate ) struct SharedContext < ' tcx > {
@@ -561,6 +565,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
561
565
562
566
let mut cx = Context {
563
567
current : Vec :: new ( ) ,
568
+ current_module_linkable_items : Default :: default ( ) ,
564
569
dst,
565
570
render_redirect_pages : false ,
566
571
id_map,
@@ -591,6 +596,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
591
596
fn make_child_renderer ( & self ) -> Self {
592
597
Self {
593
598
current : self . current . clone ( ) ,
599
+ current_module_linkable_items : self . current_module_linkable_items . clone ( ) ,
594
600
dst : self . dst . clone ( ) ,
595
601
render_redirect_pages : self . render_redirect_pages ,
596
602
deref_id_map : Default :: default ( ) ,
@@ -785,8 +791,29 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
785
791
info ! ( "Recursing into {}" , self . dst. display( ) ) ;
786
792
787
793
if !item. is_stripped ( ) {
794
+ // Populate a list of items that are directly in the module
795
+ // or inlined into it.
796
+ // When an intra-doc link or named type needs linked,
797
+ // these are preferred over more distant paths.
798
+ let ( clean:: StrippedItem ( box clean:: ModuleItem ( ref module) )
799
+ | clean:: ModuleItem ( ref module) ) = * item. kind
800
+ else {
801
+ unreachable ! ( )
802
+ } ;
803
+ self . current_module_linkable_items = Default :: default ( ) ;
804
+ for item in & module. items {
805
+ if item. is_stripped ( ) {
806
+ continue ;
807
+ }
808
+ if let Some ( def_id) = item. def_id ( )
809
+ && let Some ( name) = item. name
810
+ {
811
+ self . current_module_linkable_items . insert ( def_id, ( item. type_ ( ) , name) ) ;
812
+ }
813
+ }
814
+ // Render the current module to HTML.
815
+ // Buf will be empty if the module is stripped and there is no redirect for it.
788
816
let buf = self . render_item ( item, true ) ;
789
- // buf will be empty if the module is stripped and there is no redirect for it
790
817
if !buf. is_empty ( ) {
791
818
self . shared . ensure_dir ( & self . dst ) ?;
792
819
let joint_dst = self . dst . join ( "index.html" ) ;
0 commit comments