@@ -49,10 +49,6 @@ pub(crate) struct Context<'tcx> {
4949 /// The current destination folder of where HTML artifacts should be placed.
5050 /// This changes as the context descends into the module hierarchy.
5151 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 ,
5652 /// Tracks section IDs for `Deref` targets so they match in both the main
5753 /// body and the sidebar.
5854 pub ( super ) deref_id_map : DefIdMap < String > ,
@@ -64,21 +60,32 @@ pub(crate) struct Context<'tcx> {
6460 ///
6561 /// [#82381]: https://github.com/rust-lang/rust/issues/82381
6662 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 ,
6776 /// This flag indicates whether source links should be generated or not. If
6877 /// the source files are present in the html rendering, then this will be
6978 /// `true`.
7079 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 > ,
7380 /// Field used during rendering, to know if we're inside an inlined item.
7481 pub ( crate ) is_inside_inlined_module : bool ,
7582}
7683
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+ }
8289
8390/// Shared mutable state used in [`Context`] and elsewhere.
8491pub ( crate ) struct SharedContext < ' tcx > {
@@ -174,14 +181,16 @@ impl<'tcx> Context<'tcx> {
174181 }
175182
176183 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 ;
178185 // If the item is stripped but inlined, links won't point to the item so no need to generate
179186 // a file for it.
180187 if it. is_stripped ( )
181188 && let Some ( def_id) = it. def_id ( )
182189 && def_id. is_local ( )
183190 {
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+ {
185194 // For now we're forced to generate a redirect page for stripped items until
186195 // `record_extern_fqn` correctly points to external items.
187196 render_redirect_pages = true ;
@@ -441,6 +450,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
441450 }
442451
443452 const RUN_ON_MODULE : bool = true ;
453+ type InfoType = ContextInfo ;
444454
445455 fn init (
446456 krate : clean:: Crate ,
@@ -562,13 +572,11 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
562572 let mut cx = Context {
563573 current : Vec :: new ( ) ,
564574 dst,
565- render_redirect_pages : false ,
566575 id_map,
567576 deref_id_map : Default :: default ( ) ,
568577 shared : Rc :: new ( scx) ,
569- include_sources,
570578 types_with_notable_traits : FxIndexSet :: default ( ) ,
571- is_inside_inlined_module : false ,
579+ info : ContextInfo :: new ( include_sources ) ,
572580 } ;
573581
574582 if emit_crate {
@@ -582,18 +590,15 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
582590 Ok ( ( cx, krate) )
583591 }
584592
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;
597602 }
598603
599604 fn after_krate ( & mut self ) -> Result < ( ) , Error > {
@@ -775,8 +780,8 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
775780 // External crates will provide links to these structures, so
776781 // these modules are recursed into, but not rendered normally
777782 // (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 ( ) ;
780785 }
781786 let item_name = item. name . unwrap ( ) ;
782787 self . dst . push ( & * item_name. as_str ( ) ) ;
@@ -793,19 +798,19 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
793798 self . shared . fs . write ( joint_dst, buf) ?;
794799 }
795800 }
796- if !self . is_inside_inlined_module {
801+ if !self . info . is_inside_inlined_module {
797802 if let Some ( def_id) = item. def_id ( )
798803 && self . cache ( ) . inlined_items . contains ( & def_id)
799804 {
800- self . is_inside_inlined_module = true ;
805+ self . info . is_inside_inlined_module = true ;
801806 }
802807 } else if !self . cache ( ) . document_hidden && item. is_doc_hidden ( ) {
803808 // 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 ;
805810 }
806811
807812 // Render sidebar-items.js used throughout this module.
808- if !self . render_redirect_pages {
813+ if !self . info . render_redirect_pages {
809814 let ( clean:: StrippedItem ( box clean:: ModuleItem ( ref module) )
810815 | clean:: ModuleItem ( ref module) ) = item. kind
811816 else {
@@ -836,8 +841,8 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
836841 // External crates will provide links to these structures, so
837842 // these modules are recursed into, but not rendered normally
838843 // (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 ( ) ;
841846 }
842847
843848 let buf = self . render_item ( & item, false ) ;
@@ -850,7 +855,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
850855 let joint_dst = self . dst . join ( file_name) ;
851856 self . shared . fs . write ( joint_dst, buf) ?;
852857
853- if !self . render_redirect_pages {
858+ if !self . info . render_redirect_pages {
854859 self . shared . all . borrow_mut ( ) . append ( full_path ( self , & item) , & item_type) ;
855860 }
856861 // If the item is a macro, redirect from the old macro URL (with !)
0 commit comments