@@ -111,16 +111,16 @@ crate struct Context<'tcx> {
111
111
/// real location of an item. This is used to allow external links to
112
112
/// publicly reused items to redirect to the right location.
113
113
crate render_redirect_pages : bool ,
114
- /// The map used to ensure all generated 'id=' attributes are unique.
115
- id_map : Rc < RefCell < IdMap > > ,
116
- /// Tracks section IDs for `Deref` targets so they match in both the main
117
- /// body and the sidebar.
118
- deref_id_map : Rc < RefCell < FxHashMap < DefId , String > > > ,
119
114
crate shared : Arc < SharedContext < ' tcx > > ,
120
- all : Rc < RefCell < AllTypes > > ,
121
- /// Storage for the errors produced while generating documentation so they
122
- /// can be printed together at the end.
123
- crate errors : Rc < Receiver < String > > ,
115
+ /// The [`Cache`] used during rendering.
116
+ ///
117
+ /// Ideally the cache would be in [`SharedContext`], but it's mutated
118
+ /// between when the `SharedContext` is created and when `Context`
119
+ /// is created, so more refactoring would be needed.
120
+ ///
121
+ /// It's immutable once in `Context`, so it's not as bad that it's not in
122
+ /// `SharedContext`.
123
+ // FIXME: move `cache` to `SharedContext`
124
124
crate cache : Rc < Cache > ,
125
125
}
126
126
@@ -163,6 +163,15 @@ crate struct SharedContext<'tcx> {
163
163
crate edition : Edition ,
164
164
crate codes : ErrorCodes ,
165
165
playground : Option < markdown:: Playground > ,
166
+ /// The map used to ensure all generated 'id=' attributes are unique.
167
+ id_map : RefCell < IdMap > ,
168
+ /// Tracks section IDs for `Deref` targets so they match in both the main
169
+ /// body and the sidebar.
170
+ deref_id_map : RefCell < FxHashMap < DefId , String > > ,
171
+ all : RefCell < AllTypes > ,
172
+ /// Storage for the errors produced while generating documentation so they
173
+ /// can be printed together at the end.
174
+ crate errors : Receiver < String > ,
166
175
}
167
176
168
177
impl < ' tcx > Context < ' tcx > {
@@ -478,6 +487,10 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
478
487
edition,
479
488
codes : ErrorCodes :: from ( unstable_features. is_nightly_build ( ) ) ,
480
489
playground,
490
+ id_map : RefCell :: new ( id_map) ,
491
+ deref_id_map : RefCell :: new ( FxHashMap :: default ( ) ) ,
492
+ all : RefCell :: new ( AllTypes :: new ( ) ) ,
493
+ errors : receiver,
481
494
} ;
482
495
483
496
// Add the default themes to the `Vec` of stylepaths
@@ -504,11 +517,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
504
517
current : Vec :: new ( ) ,
505
518
dst,
506
519
render_redirect_pages : false ,
507
- id_map : Rc :: new ( RefCell :: new ( id_map) ) ,
508
- deref_id_map : Rc :: new ( RefCell :: new ( FxHashMap :: default ( ) ) ) ,
509
520
shared : Arc :: new ( scx) ,
510
- all : Rc :: new ( RefCell :: new ( AllTypes :: new ( ) ) ) ,
511
- errors : Rc :: new ( receiver) ,
512
521
cache : Rc :: new ( cache) ,
513
522
} ;
514
523
@@ -558,7 +567,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
558
567
} else {
559
568
String :: new ( )
560
569
} ;
561
- let all = self . all . replace ( AllTypes :: new ( ) ) ;
570
+ let all = self . shared . all . replace ( AllTypes :: new ( ) ) ;
562
571
let v = layout:: render (
563
572
& self . shared . layout ,
564
573
& page,
@@ -591,7 +600,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
591
600
592
601
// Flush pending errors.
593
602
Arc :: get_mut ( & mut self . shared ) . unwrap ( ) . fs . close ( ) ;
594
- let nb_errors = self . errors . iter ( ) . map ( |err| diag. struct_err ( & err) . emit ( ) ) . count ( ) ;
603
+ let nb_errors = self . shared . errors . iter ( ) . map ( |err| diag. struct_err ( & err) . emit ( ) ) . count ( ) ;
595
604
if nb_errors > 0 {
596
605
Err ( Error :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "I/O error" ) , "" ) )
597
606
} else {
@@ -670,7 +679,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
670
679
self . shared . fs . write ( & joint_dst, buf. as_bytes ( ) ) ?;
671
680
672
681
if !self . render_redirect_pages {
673
- self . all . borrow_mut ( ) . append ( full_path ( self , & item) , & item_type) ;
682
+ self . shared . all . borrow_mut ( ) . append ( full_path ( self , & item) , & item_type) ;
674
683
}
675
684
// If the item is a macro, redirect from the old macro URL (with !)
676
685
// to the new one (without).
@@ -1517,7 +1526,7 @@ fn settings(root_path: &str, suffix: &str, themes: &[StylePath]) -> Result<Strin
1517
1526
1518
1527
impl Context < ' _ > {
1519
1528
fn derive_id ( & self , id : String ) -> String {
1520
- let mut map = self . id_map . borrow_mut ( ) ;
1529
+ let mut map = self . shared . id_map . borrow_mut ( ) ;
1521
1530
map. derive ( id)
1522
1531
}
1523
1532
@@ -1572,8 +1581,8 @@ impl Context<'_> {
1572
1581
} ;
1573
1582
1574
1583
{
1575
- self . id_map . borrow_mut ( ) . reset ( ) ;
1576
- self . id_map . borrow_mut ( ) . populate ( & INITIAL_IDS ) ;
1584
+ self . shared . id_map . borrow_mut ( ) . reset ( ) ;
1585
+ self . shared . id_map . borrow_mut ( ) . populate ( & INITIAL_IDS ) ;
1577
1586
}
1578
1587
1579
1588
if !self . render_redirect_pages {
@@ -1841,7 +1850,7 @@ fn render_markdown(
1841
1850
prefix : & str ,
1842
1851
is_hidden : bool ,
1843
1852
) {
1844
- let mut ids = cx. id_map . borrow_mut ( ) ;
1853
+ let mut ids = cx. shared . id_map . borrow_mut ( ) ;
1845
1854
write ! (
1846
1855
w,
1847
1856
"<div class=\" docblock{}\" >{}{}</div>" ,
@@ -2319,7 +2328,7 @@ fn short_item_info(
2319
2328
2320
2329
if let Some ( note) = note {
2321
2330
let note = note. as_str ( ) ;
2322
- let mut ids = cx. id_map . borrow_mut ( ) ;
2331
+ let mut ids = cx. shared . id_map . borrow_mut ( ) ;
2323
2332
let html = MarkdownHtml (
2324
2333
& note,
2325
2334
& mut ids,
@@ -2358,7 +2367,7 @@ fn short_item_info(
2358
2367
message. push_str ( & format ! ( " ({})" , feature) ) ;
2359
2368
2360
2369
if let Some ( unstable_reason) = reason {
2361
- let mut ids = cx. id_map . borrow_mut ( ) ;
2370
+ let mut ids = cx. shared . id_map . borrow_mut ( ) ;
2362
2371
message = format ! (
2363
2372
"<details><summary>{}</summary>{}</details>" ,
2364
2373
message,
@@ -3513,7 +3522,8 @@ fn render_assoc_items(
3513
3522
type_. print( cx. cache( ) )
3514
3523
) ) ) ;
3515
3524
debug ! ( "Adding {} to deref id map" , type_. print( cx. cache( ) ) ) ;
3516
- cx. deref_id_map
3525
+ cx. shared
3526
+ . deref_id_map
3517
3527
. borrow_mut ( )
3518
3528
. insert ( type_. def_id_full ( cx. cache ( ) ) . unwrap ( ) , id. clone ( ) ) ;
3519
3529
write ! (
@@ -3819,7 +3829,7 @@ fn render_impl(
3819
3829
}
3820
3830
3821
3831
if let Some ( ref dox) = cx. shared . maybe_collapsed_doc_value ( & i. impl_item ) {
3822
- let mut ids = cx. id_map . borrow_mut ( ) ;
3832
+ let mut ids = cx. shared . id_map . borrow_mut ( ) ;
3823
3833
write ! (
3824
3834
w,
3825
3835
"<div class=\" docblock\" >{}</div>" ,
@@ -4448,7 +4458,7 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
4448
4458
. flat_map ( |i| get_methods ( i. inner_impl ( ) , true , & mut used_links, deref_mut, c) )
4449
4459
. collect :: < Vec < _ > > ( ) ;
4450
4460
if !ret. is_empty ( ) {
4451
- let deref_id_map = cx. deref_id_map . borrow ( ) ;
4461
+ let deref_id_map = cx. shared . deref_id_map . borrow ( ) ;
4452
4462
let id = deref_id_map
4453
4463
. get ( & real_target. def_id_full ( cx. cache ( ) ) . unwrap ( ) )
4454
4464
. expect ( "Deref section without derived id" ) ;
0 commit comments