@@ -49,10 +49,6 @@ pub(crate) struct Context<'tcx> {
49
49
/// The current destination folder of where HTML artifacts should be placed.
50
50
/// This changes as the context descends into the module hierarchy.
51
51
pub ( crate ) dst : PathBuf ,
52
- /// A flag, which when `true`, will render pages which redirect to the
53
- /// real location of an item. This is used to allow external links to
54
- /// publicly reused items to redirect to the right location.
55
- pub ( super ) render_redirect_pages : bool ,
56
52
/// Tracks section IDs for `Deref` targets so they match in both the main
57
53
/// body and the sidebar.
58
54
pub ( super ) deref_id_map : DefIdMap < String > ,
@@ -64,21 +60,32 @@ pub(crate) struct Context<'tcx> {
64
60
///
65
61
/// [#82381]: https://github.com/rust-lang/rust/issues/82381
66
62
pub ( crate ) shared : Rc < SharedContext < ' tcx > > ,
63
+ /// Collection of all types with notable traits referenced in the current module.
64
+ pub ( crate ) types_with_notable_traits : FxIndexSet < clean:: Type > ,
65
+ /// Contains information that needs to be saved and reset after rendering an item which is
66
+ /// not a module.
67
+ pub ( crate ) info : ContextInfo ,
68
+ }
69
+
70
+ #[ derive( Clone , Copy ) ]
71
+ pub ( crate ) struct ContextInfo {
72
+ /// A flag, which when `true`, will render pages which redirect to the
73
+ /// real location of an item. This is used to allow external links to
74
+ /// publicly reused items to redirect to the right location.
75
+ pub ( super ) render_redirect_pages : bool ,
67
76
/// This flag indicates whether source links should be generated or not. If
68
77
/// the source files are present in the html rendering, then this will be
69
78
/// `true`.
70
79
pub ( crate ) include_sources : bool ,
71
- /// Collection of all types with notable traits referenced in the current module.
72
- pub ( crate ) types_with_notable_traits : FxIndexSet < clean:: Type > ,
73
80
/// Field used during rendering, to know if we're inside an inlined item.
74
81
pub ( crate ) is_inside_inlined_module : bool ,
75
82
}
76
83
77
- // `Context` is cloned a lot, so we don't want the size to grow unexpectedly.
78
- # [ cfg ( all ( not ( windows ) , target_pointer_width = "64" ) ) ]
79
- rustc_data_structures :: static_assert_size! ( Context < ' _> , 192 ) ;
80
- # [ cfg ( all ( windows , target_pointer_width = "64" ) ) ]
81
- rustc_data_structures :: static_assert_size! ( Context < ' _> , 200 ) ;
84
+ impl ContextInfo {
85
+ fn new ( include_sources : bool ) -> Self {
86
+ Self { render_redirect_pages : false , include_sources , is_inside_inlined_module : false }
87
+ }
88
+ }
82
89
83
90
/// Shared mutable state used in [`Context`] and elsewhere.
84
91
pub ( crate ) struct SharedContext < ' tcx > {
@@ -174,14 +181,16 @@ impl<'tcx> Context<'tcx> {
174
181
}
175
182
176
183
fn render_item ( & mut self , it : & clean:: Item , is_module : bool ) -> String {
177
- let mut render_redirect_pages = self . render_redirect_pages ;
184
+ let mut render_redirect_pages = self . info . render_redirect_pages ;
178
185
// If the item is stripped but inlined, links won't point to the item so no need to generate
179
186
// a file for it.
180
187
if it. is_stripped ( )
181
188
&& let Some ( def_id) = it. def_id ( )
182
189
&& def_id. is_local ( )
183
190
{
184
- if self . is_inside_inlined_module || self . shared . cache . inlined_items . contains ( & def_id) {
191
+ if self . info . is_inside_inlined_module
192
+ || self . shared . cache . inlined_items . contains ( & def_id)
193
+ {
185
194
// For now we're forced to generate a redirect page for stripped items until
186
195
// `record_extern_fqn` correctly points to external items.
187
196
render_redirect_pages = true ;
@@ -441,6 +450,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
441
450
}
442
451
443
452
const RUN_ON_MODULE : bool = true ;
453
+ type InfoType = ContextInfo ;
444
454
445
455
fn init (
446
456
krate : clean:: Crate ,
@@ -562,13 +572,11 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
562
572
let mut cx = Context {
563
573
current : Vec :: new ( ) ,
564
574
dst,
565
- render_redirect_pages : false ,
566
575
id_map,
567
576
deref_id_map : Default :: default ( ) ,
568
577
shared : Rc :: new ( scx) ,
569
- include_sources,
570
578
types_with_notable_traits : FxIndexSet :: default ( ) ,
571
- is_inside_inlined_module : false ,
579
+ info : ContextInfo :: new ( include_sources ) ,
572
580
} ;
573
581
574
582
if emit_crate {
@@ -582,18 +590,15 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
582
590
Ok ( ( cx, krate) )
583
591
}
584
592
585
- fn make_child_renderer ( & self ) -> Self {
586
- Self {
587
- current : self . current . clone ( ) ,
588
- dst : self . dst . clone ( ) ,
589
- render_redirect_pages : self . render_redirect_pages ,
590
- deref_id_map : Default :: default ( ) ,
591
- id_map : IdMap :: new ( ) ,
592
- shared : Rc :: clone ( & self . shared ) ,
593
- include_sources : self . include_sources ,
594
- types_with_notable_traits : FxIndexSet :: default ( ) ,
595
- is_inside_inlined_module : self . is_inside_inlined_module ,
596
- }
593
+ fn make_child_renderer ( & mut self ) -> Self :: InfoType {
594
+ self . deref_id_map . clear ( ) ;
595
+ self . id_map . clear ( ) ;
596
+ self . types_with_notable_traits . clear ( ) ;
597
+ self . info
598
+ }
599
+
600
+ fn set_back_info ( & mut self , info : Self :: InfoType ) {
601
+ self . info = info;
597
602
}
598
603
599
604
fn after_krate ( & mut self ) -> Result < ( ) , Error > {
@@ -775,8 +780,8 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
775
780
// External crates will provide links to these structures, so
776
781
// these modules are recursed into, but not rendered normally
777
782
// (a flag on the context).
778
- if !self . render_redirect_pages {
779
- self . render_redirect_pages = item. is_stripped ( ) ;
783
+ if !self . info . render_redirect_pages {
784
+ self . info . render_redirect_pages = item. is_stripped ( ) ;
780
785
}
781
786
let item_name = item. name . unwrap ( ) ;
782
787
self . dst . push ( & * item_name. as_str ( ) ) ;
@@ -793,19 +798,19 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
793
798
self . shared . fs . write ( joint_dst, buf) ?;
794
799
}
795
800
}
796
- if !self . is_inside_inlined_module {
801
+ if !self . info . is_inside_inlined_module {
797
802
if let Some ( def_id) = item. def_id ( )
798
803
&& self . cache ( ) . inlined_items . contains ( & def_id)
799
804
{
800
- self . is_inside_inlined_module = true ;
805
+ self . info . is_inside_inlined_module = true ;
801
806
}
802
807
} else if !self . cache ( ) . document_hidden && item. is_doc_hidden ( ) {
803
808
// We're not inside an inlined module anymore since this one cannot be re-exported.
804
- self . is_inside_inlined_module = false ;
809
+ self . info . is_inside_inlined_module = false ;
805
810
}
806
811
807
812
// Render sidebar-items.js used throughout this module.
808
- if !self . render_redirect_pages {
813
+ if !self . info . render_redirect_pages {
809
814
let ( clean:: StrippedItem ( box clean:: ModuleItem ( ref module) )
810
815
| clean:: ModuleItem ( ref module) ) = item. kind
811
816
else {
@@ -836,8 +841,8 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
836
841
// External crates will provide links to these structures, so
837
842
// these modules are recursed into, but not rendered normally
838
843
// (a flag on the context).
839
- if !self . render_redirect_pages {
840
- self . render_redirect_pages = item. is_stripped ( ) ;
844
+ if !self . info . render_redirect_pages {
845
+ self . info . render_redirect_pages = item. is_stripped ( ) ;
841
846
}
842
847
843
848
let buf = self . render_item ( & item, false ) ;
@@ -850,7 +855,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
850
855
let joint_dst = self . dst . join ( file_name) ;
851
856
self . shared . fs . write ( joint_dst, buf) ?;
852
857
853
- if !self . render_redirect_pages {
858
+ if !self . info . render_redirect_pages {
854
859
self . shared . all . borrow_mut ( ) . append ( full_path ( self , & item) , & item_type) ;
855
860
}
856
861
// If the item is a macro, redirect from the old macro URL (with !)
0 commit comments