@@ -55,9 +55,9 @@ pub(crate) struct Context<'tcx> {
55
55
pub(super) render_redirect_pages: bool,
56
56
/// Tracks section IDs for `Deref` targets so they match in both the main
57
57
/// body and the sidebar.
58
- pub(super) deref_id_map: RefCell< FxHashMap<DefId, String> >,
58
+ pub(super) deref_id_map: FxHashMap<DefId, String>,
59
59
/// The map used to ensure all generated 'id=' attributes are unique.
60
- pub(super) id_map: RefCell< IdMap> ,
60
+ pub(super) id_map: IdMap,
61
61
/// Shared mutable state.
62
62
///
63
63
/// Issue for improving the situation: [#82381][]
@@ -72,7 +72,7 @@ pub(crate) struct Context<'tcx> {
72
72
73
73
// `Context` is cloned a lot, so we don't want the size to grow unexpectedly.
74
74
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
75
- rustc_data_structures::static_assert_size!(Context<'_>, 144 );
75
+ rustc_data_structures::static_assert_size!(Context<'_>, 128 );
76
76
77
77
/// Shared mutable state used in [`Context`] and elsewhere.
78
78
pub(crate) struct SharedContext<'tcx> {
@@ -155,9 +155,8 @@ impl<'tcx> Context<'tcx> {
155
155
self.shared.tcx.sess
156
156
}
157
157
158
- pub(super) fn derive_id(&self, id: String) -> String {
159
- let mut map = self.id_map.borrow_mut();
160
- map.derive(id)
158
+ pub(super) fn derive_id(&mut self, id: String) -> String {
159
+ self.id_map.derive(id)
161
160
}
162
161
163
162
/// String representation of how to get back to the root path of the 'doc/'
@@ -166,7 +165,7 @@ impl<'tcx> Context<'tcx> {
166
165
"../".repeat(self.current.len())
167
166
}
168
167
169
- fn render_item(&self, it: &clean::Item, is_module: bool) -> String {
168
+ fn render_item(&mut self, it: &clean::Item, is_module: bool) -> String {
170
169
let mut title = String::new();
171
170
if !is_module {
172
171
title.push_str(it.name.unwrap().as_str());
@@ -203,23 +202,26 @@ impl<'tcx> Context<'tcx> {
203
202
};
204
203
205
204
if !self.render_redirect_pages {
205
+ let clone_shared = Rc::clone(&self.shared);
206
206
let page = layout::Page {
207
207
css_class: tyname_s,
208
208
root_path: &self.root_path(),
209
- static_root_path: self.shared .static_root_path.as_deref(),
209
+ static_root_path: clone_shared .static_root_path.as_deref(),
210
210
title: &title,
211
211
description: &desc,
212
212
keywords: &keywords,
213
- resource_suffix: &self.shared .resource_suffix,
213
+ resource_suffix: &clone_shared .resource_suffix,
214
214
extra_scripts: &[],
215
215
static_extra_scripts: &[],
216
216
};
217
+ let mut page_buffer = Buffer::html();
218
+ print_item(self, it, &mut page_buffer, &page);
217
219
layout::render(
218
- &self.shared .layout,
220
+ &clone_shared .layout,
219
221
&page,
220
222
|buf: &mut _| print_sidebar(self, it, buf),
221
- |buf: &mut _| print_item(self, it, buf, &page ),
222
- &self.shared .style_files,
223
+ move |buf: &mut Buffer| buf.push_buffer(page_buffer ),
224
+ &clone_shared .style_files,
223
225
)
224
226
} else {
225
227
if let Some(&(ref names, ty)) = self.cache().paths.get(&it.item_id.expect_def_id()) {
@@ -512,8 +514,8 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
512
514
current: Vec::new(),
513
515
dst,
514
516
render_redirect_pages: false,
515
- id_map: RefCell::new(id_map) ,
516
- deref_id_map: RefCell::new( FxHashMap::default() ),
517
+ id_map,
518
+ deref_id_map: FxHashMap::default(),
517
519
shared: Rc::new(scx),
518
520
include_sources,
519
521
};
@@ -528,7 +530,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
528
530
529
531
// Write shared runs within a flock; disable thread dispatching of IO temporarily.
530
532
Rc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(true);
531
- write_shared(&cx, &krate, index, &md_opts)?;
533
+ write_shared(&mut cx, &krate, index, &md_opts)?;
532
534
Rc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(false);
533
535
}
534
536
@@ -540,8 +542,8 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
540
542
current: self.current.clone(),
541
543
dst: self.dst.clone(),
542
544
render_redirect_pages: self.render_redirect_pages,
543
- deref_id_map: RefCell::new( FxHashMap::default() ),
544
- id_map: RefCell::new( IdMap::new() ),
545
+ deref_id_map: FxHashMap::default(),
546
+ id_map: IdMap::new(),
545
547
shared: Rc::clone(&self.shared),
546
548
include_sources: self.include_sources,
547
549
}
@@ -557,31 +559,32 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
557
559
if !root_path.ends_with('/') {
558
560
root_path.push('/');
559
561
}
562
+ let shared = Rc::clone(&self.shared);
560
563
let mut page = layout::Page {
561
564
title: "List of all items in this crate",
562
565
css_class: "mod",
563
566
root_path: "../",
564
- static_root_path: self. shared.static_root_path.as_deref(),
567
+ static_root_path: shared.static_root_path.as_deref(),
565
568
description: "List of all items in this crate",
566
569
keywords: BASIC_KEYWORDS,
567
- resource_suffix: &self. shared.resource_suffix,
570
+ resource_suffix: &shared.resource_suffix,
568
571
extra_scripts: &[],
569
572
static_extra_scripts: &[],
570
573
};
571
- let sidebar = if self. shared.cache.crate_version.is_some() {
574
+ let sidebar = if shared.cache.crate_version.is_some() {
572
575
format!("<h2 class=\"location\">Crate {}</h2>", crate_name)
573
576
} else {
574
577
String::new()
575
578
};
576
- let all = self. shared.all.replace(AllTypes::new());
579
+ let all = shared.all.replace(AllTypes::new());
577
580
let v = layout::render(
578
- &self. shared.layout,
581
+ &shared.layout,
579
582
&page,
580
583
sidebar,
581
584
|buf: &mut Buffer| all.print(buf),
582
- &self. shared.style_files,
585
+ &shared.style_files,
583
586
);
584
- self. shared.fs.write(final_file, v)?;
587
+ shared.fs.write(final_file, v)?;
585
588
586
589
// Generating settings page.
587
590
page.title = "Rustdoc settings";
@@ -590,7 +593,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
590
593
591
594
let sidebar = "<h2 class=\"location\">Settings</h2><div class=\"sidebar-elems\"></div>";
592
595
let v = layout::render(
593
- &self. shared.layout,
596
+ &shared.layout,
594
597
&page,
595
598
sidebar,
596
599
|buf: &mut Buffer| {
@@ -613,33 +616,36 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
613
616
suffix = page.resource_suffix,
614
617
)
615
618
},
616
- &self. shared.style_files,
619
+ &shared.style_files,
617
620
);
618
- self. shared.fs.write(settings_file, v)?;
621
+ shared.fs.write(settings_file, v)?;
619
622
620
- if self. shared.layout.scrape_examples_extension {
623
+ if shared.layout.scrape_examples_extension {
621
624
page.title = "About scraped examples";
622
625
page.description = "How the scraped examples feature works in Rustdoc";
623
626
let v = layout::render(
624
- &self. shared.layout,
627
+ &shared.layout,
625
628
&page,
626
629
"",
627
- scrape_examples_help(&*self. shared),
628
- &self. shared.style_files,
630
+ scrape_examples_help(&*shared),
631
+ &shared.style_files,
629
632
);
630
- self. shared.fs.write(scrape_examples_help_file, v)?;
633
+ shared.fs.write(scrape_examples_help_file, v)?;
631
634
}
632
635
633
- if let Some(ref redirections) = self. shared.redirections {
636
+ if let Some(ref redirections) = shared.redirections {
634
637
if !redirections.borrow().is_empty() {
635
638
let redirect_map_path =
636
639
self.dst.join(crate_name.as_str()).join("redirect-map.json");
637
640
let paths = serde_json::to_string(&*redirections.borrow()).unwrap();
638
- self. shared.ensure_dir(&self.dst.join(crate_name.as_str()))?;
639
- self. shared.fs.write(redirect_map_path, paths)?;
641
+ shared.ensure_dir(&self.dst.join(crate_name.as_str()))?;
642
+ shared.fs.write(redirect_map_path, paths)?;
640
643
}
641
644
}
642
645
646
+ // No need for it anymore.
647
+ drop(shared);
648
+
643
649
// Flush pending errors.
644
650
Rc::get_mut(&mut self.shared).unwrap().fs.close();
645
651
let nb_errors =
@@ -662,7 +668,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
662
668
if !self.render_redirect_pages {
663
669
self.render_redirect_pages = item.is_stripped();
664
670
}
665
- let scx = &self.shared;
666
671
let item_name = item.name.unwrap();
667
672
self.dst.push(&*item_name.as_str());
668
673
self.current.push(item_name);
@@ -674,7 +679,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
674
679
if !buf.is_empty() {
675
680
self.shared.ensure_dir(&self.dst)?;
676
681
let joint_dst = self.dst.join("index.html");
677
- scx .fs.write(joint_dst, buf)?;
682
+ self.shared .fs.write(joint_dst, buf)?;
678
683
}
679
684
680
685
// Render sidebar-items.js used throughout this module.
@@ -684,7 +689,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
684
689
let items = self.build_sidebar_items(module);
685
690
let js_dst = self.dst.join(&format!("sidebar-items{}.js", self.shared.resource_suffix));
686
691
let v = format!("initSidebarItems({});", serde_json::to_string(&items).unwrap());
687
- scx .fs.write(js_dst, v)?;
692
+ self.shared .fs.write(js_dst, v)?;
688
693
}
689
694
Ok(())
690
695
}
0 commit comments