(mut w: W, cx: &Context<'_>, item: &clean::Item) {
let tcx = cx.tcx();
let def_id = item.item_id.expect_def_id();
let key = tcx.def_path_hash(def_id);
let Some(call_locations) = cx.shared.call_locations.get(&key) else { return };
// Generate a unique ID so users can link to this section for a given method
- let id = cx.id_map.derive("scraped-examples");
+ let id = cx.derive_id("scraped-examples");
write!(
&mut w,
"\
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index a86b7966c260..4c8d704e65bc 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -1,7 +1,5 @@
-use std::cell::{RefCell, RefMut};
use std::cmp::Ordering;
use std::fmt;
-use std::rc::Rc;
use itertools::Itertools;
use rinja::Template;
@@ -61,7 +59,7 @@ macro_rules! item_template {
(
$(#[$meta:meta])*
struct $name:ident<'a, 'cx> {
- cx: RefCell<&'a mut Context<'cx>>,
+ cx: &'a Context<'cx>,
it: &'a clean::Item,
$($field_name:ident: $field_ty:ty),*,
},
@@ -70,14 +68,14 @@ macro_rules! item_template {
#[derive(Template)]
$(#[$meta])*
struct $name<'a, 'cx> {
- cx: RefCell<&'a mut Context<'cx>>,
+ cx: &'a Context<'cx>,
it: &'a clean::Item,
$($field_name: $field_ty),*
}
impl<'a, 'cx: 'a> ItemTemplate<'a, 'cx> for $name<'a, 'cx> {
- fn item_and_mut_cx(&self) -> (&'a clean::Item, RefMut<'_, &'a mut Context<'cx>>) {
- (&self.it, self.cx.borrow_mut())
+ fn item_and_cx(&self) -> (&'a clean::Item, &'a Context<'cx>) {
+ (&self.it, &self.cx)
}
}
@@ -95,8 +93,8 @@ macro_rules! item_template_methods {
(document $($rest:tt)*) => {
fn document<'b>(&'b self) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> {
display_fn(move |f| {
- let (item, mut cx) = self.item_and_mut_cx();
- let v = document(*cx, item, None, HeadingOffset::H2);
+ let (item, cx) = self.item_and_cx();
+ let v = document(cx, item, None, HeadingOffset::H2);
write!(f, "{v}")
})
}
@@ -105,9 +103,9 @@ macro_rules! item_template_methods {
(document_type_layout $($rest:tt)*) => {
fn document_type_layout<'b>(&'b self) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> {
display_fn(move |f| {
- let (item, cx) = self.item_and_mut_cx();
+ let (item, cx) = self.item_and_cx();
let def_id = item.item_id.expect_def_id();
- let v = document_type_layout(*cx, def_id);
+ let v = document_type_layout(cx, def_id);
write!(f, "{v}")
})
}
@@ -116,8 +114,8 @@ macro_rules! item_template_methods {
(render_attributes_in_pre $($rest:tt)*) => {
fn render_attributes_in_pre<'b>(&'b self) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> {
display_fn(move |f| {
- let (item, cx) = self.item_and_mut_cx();
- let v = render_attributes_in_pre(item, "", &cx);
+ let (item, cx) = self.item_and_cx();
+ let v = render_attributes_in_pre(item, "", cx);
write!(f, "{v}")
})
}
@@ -126,9 +124,9 @@ macro_rules! item_template_methods {
(render_assoc_items $($rest:tt)*) => {
fn render_assoc_items<'b>(&'b self) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> {
display_fn(move |f| {
- let (item, mut cx) = self.item_and_mut_cx();
+ let (item, cx) = self.item_and_cx();
let def_id = item.item_id.expect_def_id();
- let v = render_assoc_items(*cx, item, def_id, AssocItemRender::All);
+ let v = render_assoc_items(cx, item, def_id, AssocItemRender::All);
write!(f, "{v}")
})
}
@@ -175,7 +173,7 @@ fn print_where_clause_and_check<'a, 'tcx: 'a>(
len_before != buffer.len()
}
-pub(super) fn print_item(cx: &mut Context<'_>, item: &clean::Item, buf: &mut Buffer) {
+pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer) {
debug_assert!(!item.is_stripped());
let typ = match item.kind {
clean::ModuleItem(_) => {
@@ -277,13 +275,14 @@ pub(super) fn print_item(cx: &mut Context<'_>, item: &clean::Item, buf: &mut Buf
}
// Render notable-traits.js used for all methods in this module.
- if !cx.types_with_notable_traits.is_empty() {
+ let mut types_with_notable_traits = cx.types_with_notable_traits.borrow_mut();
+ if !types_with_notable_traits.is_empty() {
write!(
buf,
r#""#,
- notable_traits_json(cx.types_with_notable_traits.iter(), cx)
+ notable_traits_json(types_with_notable_traits.iter(), cx)
);
- cx.types_with_notable_traits.clear();
+ types_with_notable_traits.clear();
}
}
@@ -308,10 +307,10 @@ fn toggle_close(mut w: impl fmt::Write) {
}
trait ItemTemplate<'a, 'cx: 'a>: rinja::Template + fmt::Display {
- fn item_and_mut_cx(&self) -> (&'a clean::Item, RefMut<'_, &'a mut Context<'cx>>);
+ fn item_and_cx(&self) -> (&'a clean::Item, &'a Context<'cx>);
}
-fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: &[clean::Item]) {
+fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) {
write!(w, "{}", document(cx, item, None, HeadingOffset::H2));
let mut not_stripped_items =
@@ -594,7 +593,7 @@ fn extra_info_tags<'a, 'tcx: 'a>(
})
}
-fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &clean::Function) {
+fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::Function) {
let tcx = cx.tcx();
let header = it.fn_header(tcx).expect("printing a function which isn't a function");
debug!(
@@ -649,7 +648,7 @@ fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &cle
write!(w, "{}", document(cx, it, None, HeadingOffset::H2));
}
-fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::Trait) {
+fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) {
let tcx = cx.tcx();
let bounds = bounds(&t.bounds, false, cx);
let required_types = t.items.iter().filter(|m| m.is_ty_associated_type()).collect::>();
@@ -801,7 +800,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
// Trait documentation
write!(w, "{}", document(cx, it, None, HeadingOffset::H2));
- fn trait_item(w: &mut Buffer, cx: &mut Context<'_>, m: &clean::Item, t: &clean::Item) {
+ fn trait_item(w: &mut Buffer, cx: &Context<'_>, m: &clean::Item, t: &clean::Item) {
let name = m.name.unwrap();
info!("Documenting {name} on {ty_name:?}", ty_name = t.name);
let item_type = m.type_();
@@ -929,8 +928,6 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
// If there are methods directly on this trait object, render them here.
write!(w, "{}", render_assoc_items(cx, it, it.item_id.expect_def_id(), AssocItemRender::All));
- let cloned_shared = Rc::clone(&cx.shared);
- let cache = &cloned_shared.cache;
let mut extern_crates = FxIndexSet::default();
if !t.is_dyn_compatible(cx.tcx()) {
@@ -950,12 +947,13 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
);
}
- if let Some(implementors) = cache.implementors.get(&it.item_id.expect_def_id()) {
+ if let Some(implementors) = cx.shared.cache.implementors.get(&it.item_id.expect_def_id()) {
// The DefId is for the first Type found with that name. The bool is
// if any Types with the same name but different DefId have been found.
let mut implementor_dups: FxHashMap = FxHashMap::default();
for implementor in implementors {
- if let Some(did) = implementor.inner_impl().for_.without_borrowed_ref().def_id(cache)
+ if let Some(did) =
+ implementor.inner_impl().for_.without_borrowed_ref().def_id(&cx.shared.cache)
&& !did.is_local()
{
extern_crates.insert(did.krate);
@@ -1036,7 +1034,10 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
it,
w,
&implementor_dups,
- &collect_paths_for_type(implementor.inner_impl().for_.clone(), cache),
+ &collect_paths_for_type(
+ implementor.inner_impl().for_.clone(),
+ &cx.shared.cache,
+ ),
);
}
w.write_str("
");
@@ -1139,8 +1140,8 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
.chain(std::iter::once("trait.impl"))
.collect();
if let Some(did) = it.item_id.as_def_id()
- && let get_extern = { || cache.external_paths.get(&did).map(|s| &s.0) }
- && let Some(fqp) = cache.exact_paths.get(&did).or_else(get_extern)
+ && let get_extern = { || cx.shared.cache.external_paths.get(&did).map(|s| &s.0) }
+ && let Some(fqp) = cx.shared.cache.exact_paths.get(&did).or_else(get_extern)
{
js_src_path.extend(fqp[..fqp.len() - 1].iter().copied());
js_src_path.push_fmt(format_args!("{}.{}.js", it.type_(), fqp.last().unwrap()));
@@ -1164,7 +1165,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
fn item_trait_alias(
w: &mut impl fmt::Write,
- cx: &mut Context<'_>,
+ cx: &Context<'_>,
it: &clean::Item,
t: &clean::TraitAlias,
) {
@@ -1190,7 +1191,7 @@ fn item_trait_alias(
.unwrap();
}
-fn item_type_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::TypeAlias) {
+fn item_type_alias(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::TypeAlias) {
wrap_item(w, |w| {
write!(
w,
@@ -1355,8 +1356,7 @@ fn item_type_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &c
//
// [JSONP]: https://en.wikipedia.org/wiki/JSONP
// [^115718]: https://github.com/rust-lang/rust/issues/115718
- let cloned_shared = Rc::clone(&cx.shared);
- let cache = &cloned_shared.cache;
+ let cache = &cx.shared.cache;
if let Some(target_did) = t.type_.def_id(cache) &&
let get_extern = { || cache.external_paths.get(&target_did) } &&
let Some(&(ref target_fqp, target_type)) = cache.paths.get(&target_did).or_else(get_extern) &&
@@ -1380,11 +1380,11 @@ fn item_type_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &c
}
}
-fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean::Union) {
+fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Union) {
item_template!(
#[template(path = "item_union.html")]
struct ItemUnion<'a, 'cx> {
- cx: RefCell<&'a mut Context<'cx>>,
+ cx: &'a Context<'cx>,
it: &'a clean::Item,
s: &'a clean::Union,
},
@@ -1394,8 +1394,7 @@ fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean:
impl<'a, 'cx: 'a> ItemUnion<'a, 'cx> {
fn render_union<'b>(&'b self) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> {
display_fn(move |f| {
- let cx = self.cx.borrow_mut();
- let v = render_union(self.it, Some(&self.s.generics), &self.s.fields, *cx);
+ let v = render_union(self.it, Some(&self.s.generics), &self.s.fields, self.cx);
write!(f, "{v}")
})
}
@@ -1405,15 +1404,13 @@ fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean:
field: &'a clean::Item,
) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> {
display_fn(move |f| {
- let mut cx = self.cx.borrow_mut();
- let v = document(*cx, field, Some(self.it), HeadingOffset::H3);
+ let v = document(self.cx, field, Some(self.it), HeadingOffset::H3);
write!(f, "{v}")
})
}
fn stability_field(&self, field: &clean::Item) -> Option {
- let cx = self.cx.borrow();
- field.stability_class(cx.tcx())
+ field.stability_class(self.cx.tcx())
}
fn print_ty<'b>(
@@ -1421,8 +1418,7 @@ fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean:
ty: &'a clean::Type,
) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> {
display_fn(move |f| {
- let cx = self.cx.borrow();
- let v = ty.print(*cx);
+ let v = ty.print(&self.cx);
write!(f, "{v}")
})
}
@@ -1441,7 +1437,7 @@ fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean:
}
}
- ItemUnion { cx: RefCell::new(cx), it, s }.render_into(w).unwrap();
+ ItemUnion { cx, it, s }.render_into(w).unwrap();
}
fn print_tuple_struct_fields<'a, 'cx: 'a>(
@@ -1471,7 +1467,7 @@ fn print_tuple_struct_fields<'a, 'cx: 'a>(
})
}
-fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::Enum) {
+fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum) {
let count_variants = e.variants().count();
wrap_item(w, |w| {
render_attributes_in_code(w, it, cx);
@@ -1532,7 +1528,7 @@ fn should_show_enum_discriminant(
fn display_c_like_variant(
w: &mut Buffer,
- cx: &mut Context<'_>,
+ cx: &Context<'_>,
item: &clean::Item,
variant: &clean::Variant,
index: VariantIdx,
@@ -1557,7 +1553,7 @@ fn display_c_like_variant(
fn render_enum_fields(
mut w: &mut Buffer,
- cx: &mut Context<'_>,
+ cx: &Context<'_>,
g: Option<&clean::Generics>,
variants: &IndexVec,
count_variants: usize,
@@ -1621,7 +1617,7 @@ fn render_enum_fields(
fn item_variants(
w: &mut Buffer,
- cx: &mut Context<'_>,
+ cx: &Context<'_>,
it: &clean::Item,
variants: &IndexVec,
enum_def_id: DefId,
@@ -1743,7 +1739,7 @@ fn item_variants(
write!(w, "