@@ -2,7 +2,6 @@ use std::cell::RefCell;
2
2
use std:: collections:: BTreeMap ;
3
3
use std:: io;
4
4
use std:: path:: { Path , PathBuf } ;
5
- use std:: rc:: Rc ;
6
5
use std:: sync:: mpsc:: { Receiver , channel} ;
7
6
8
7
use rinja:: Template ;
@@ -51,17 +50,17 @@ pub(crate) struct Context<'tcx> {
51
50
pub ( crate ) dst : PathBuf ,
52
51
/// Tracks section IDs for `Deref` targets so they match in both the main
53
52
/// body and the sidebar.
54
- pub ( super ) deref_id_map : DefIdMap < String > ,
53
+ pub ( super ) deref_id_map : RefCell < DefIdMap < String > > ,
55
54
/// The map used to ensure all generated 'id=' attributes are unique.
56
- pub ( super ) id_map : IdMap ,
55
+ pub ( super ) id_map : RefCell < IdMap > ,
57
56
/// Shared mutable state.
58
57
///
59
58
/// Issue for improving the situation: [#82381][]
60
59
///
61
60
/// [#82381]: https://github.com/rust-lang/rust/issues/82381
62
- pub ( crate ) shared : Rc < SharedContext < ' tcx > > ,
61
+ pub ( crate ) shared : SharedContext < ' tcx > ,
63
62
/// Collection of all types with notable traits referenced in the current module.
64
- pub ( crate ) types_with_notable_traits : FxIndexSet < clean:: Type > ,
63
+ pub ( crate ) types_with_notable_traits : RefCell < FxIndexSet < clean:: Type > > ,
65
64
/// Contains information that needs to be saved and reset after rendering an item which is
66
65
/// not a module.
67
66
pub ( crate ) info : ContextInfo ,
@@ -170,8 +169,8 @@ impl<'tcx> Context<'tcx> {
170
169
self . shared . tcx . sess
171
170
}
172
171
173
- pub ( super ) fn derive_id < S : AsRef < str > + ToString > ( & mut self , id : S ) -> String {
174
- self . id_map . derive ( id)
172
+ pub ( super ) fn derive_id < S : AsRef < str > + ToString > ( & self , id : S ) -> String {
173
+ self . id_map . borrow_mut ( ) . derive ( id)
175
174
}
176
175
177
176
/// String representation of how to get back to the root path of the 'doc/'
@@ -230,24 +229,23 @@ impl<'tcx> Context<'tcx> {
230
229
} ;
231
230
232
231
if !render_redirect_pages {
233
- let clone_shared = Rc :: clone ( & self . shared ) ;
232
+ let mut page_buffer = Buffer :: html ( ) ;
233
+ print_item ( self , it, & mut page_buffer) ;
234
234
let page = layout:: Page {
235
235
css_class : tyname_s,
236
236
root_path : & self . root_path ( ) ,
237
- static_root_path : clone_shared . static_root_path . as_deref ( ) ,
237
+ static_root_path : self . shared . static_root_path . as_deref ( ) ,
238
238
title : & title,
239
239
description : & desc,
240
- resource_suffix : & clone_shared . resource_suffix ,
240
+ resource_suffix : & self . shared . resource_suffix ,
241
241
rust_logo : has_doc_flag ( self . tcx ( ) , LOCAL_CRATE . as_def_id ( ) , sym:: rust_logo) ,
242
242
} ;
243
- let mut page_buffer = Buffer :: html ( ) ;
244
- print_item ( self , it, & mut page_buffer) ;
245
243
layout:: render (
246
- & clone_shared . layout ,
244
+ & self . shared . layout ,
247
245
& page,
248
246
|buf : & mut _ | print_sidebar ( self , it, buf) ,
249
247
move |buf : & mut Buffer | buf. push_buffer ( page_buffer) ,
250
- & clone_shared . style_files ,
248
+ & self . shared . style_files ,
251
249
)
252
250
} else {
253
251
if let Some ( & ( ref names, ty) ) = self . cache ( ) . paths . get ( & it. item_id . expect_def_id ( ) ) {
@@ -572,10 +570,10 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
572
570
let mut cx = Context {
573
571
current : Vec :: new ( ) ,
574
572
dst,
575
- id_map,
573
+ id_map : RefCell :: new ( id_map ) ,
576
574
deref_id_map : Default :: default ( ) ,
577
- shared : Rc :: new ( scx) ,
578
- types_with_notable_traits : FxIndexSet :: default ( ) ,
575
+ shared : scx,
576
+ types_with_notable_traits : RefCell :: new ( FxIndexSet :: default ( ) ) ,
579
577
info : ContextInfo :: new ( include_sources) ,
580
578
} ;
581
579
@@ -591,9 +589,9 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
591
589
}
592
590
593
591
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 ( ) ;
592
+ self . deref_id_map . borrow_mut ( ) . clear ( ) ;
593
+ self . id_map . borrow_mut ( ) . clear ( ) ;
594
+ self . types_with_notable_traits . borrow_mut ( ) . clear ( ) ;
597
595
self . info
598
596
}
599
597
@@ -612,7 +610,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
612
610
if !root_path. ends_with ( '/' ) {
613
611
root_path. push ( '/' ) ;
614
612
}
615
- let shared = Rc :: clone ( & self . shared ) ;
613
+ let shared = & self . shared ;
616
614
let mut page = layout:: Page {
617
615
title : "List of all items in this crate" ,
618
616
css_class : "mod sys" ,
@@ -759,11 +757,8 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
759
757
shared. fs . write ( redirect_map_path, paths) ?;
760
758
}
761
759
762
- // No need for it anymore.
763
- drop ( shared) ;
764
-
765
760
// Flush pending errors.
766
- Rc :: get_mut ( & mut self . shared ) . unwrap ( ) . fs . close ( ) ;
761
+ self . shared . fs . close ( ) ;
767
762
let nb_errors = self . shared . errors . iter ( ) . map ( |err| self . tcx ( ) . dcx ( ) . err ( err) ) . count ( ) ;
768
763
if nb_errors > 0 {
769
764
Err ( Error :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "I/O error" ) , "" ) )
0 commit comments