diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index a116ed686d90e..03454bb8b7ff0 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -2329,14 +2329,14 @@ impl Clean Crate {}
");
+ if end_newline {
+ clause.push_str(" where");
+ } else {
+ clause.push_str(" where");
+ }
}
+ for (i, pred) in gens.where_predicates.iter().enumerate() {
+ if f.alternate() {
+ clause.push(' ');
+ } else {
+ clause.push_str("
");
+ }
- match pred {
- clean::WherePredicate::BoundPredicate { ty, bounds } => {
- let bounds = bounds;
- if f.alternate() {
- clause.push_str(&format!(
- "{:#}: {:#}",
- ty.print(),
- print_generic_bounds(bounds)
- ));
- } else {
+ match pred {
+ clean::WherePredicate::BoundPredicate { ty, bounds } => {
+ let bounds = bounds;
+ if f.alternate() {
+ clause.push_str(&format!(
+ "{:#}: {:#}",
+ ty.print(cache),
+ print_generic_bounds(bounds, cache)
+ ));
+ } else {
+ clause.push_str(&format!(
+ "{}: {}",
+ ty.print(cache),
+ print_generic_bounds(bounds, cache)
+ ));
+ }
+ }
+ clean::WherePredicate::RegionPredicate { lifetime, bounds } => {
clause.push_str(&format!(
"{}: {}",
- ty.print(),
- print_generic_bounds(bounds)
+ lifetime.print(),
+ bounds
+ .iter()
+ .map(|b| b.print(cache).to_string())
+ .collect::
tags and breaking spaces still renders properly
- if f.alternate() {
- clause.push(' ');
- } else {
- clause.push_str(" ");
+ if end_newline {
+ // add a space so stripping
tags and breaking spaces still renders properly
+ if f.alternate() {
+ clause.push(' ');
+ } else {
+ clause.push_str(" ");
+ }
}
- }
- if !f.alternate() {
- clause.push_str("
", &format!("
{}", padding));
- clause.insert_str(0, &" ".repeat(indent.saturating_sub(1)));
- if !end_newline {
- clause.insert_str(0, "
");
+ if !f.alternate() {
+ clause.push_str("");
+ let padding = " ".repeat(indent + 4);
+ clause = clause.replace("
", &format!("
{}", padding));
+ clause.insert_str(0, &" ".repeat(indent.saturating_sub(1)));
+ if !end_newline {
+ clause.insert_str(0, "
");
+ }
}
- }
- write!(f, "{}", clause)
+ write!(f, "{}", clause)
+ })
}
}
@@ -327,34 +340,34 @@ impl clean::Constant {
}
impl clean::PolyTrait {
- fn print(&self) -> impl fmt::Display + '_ {
+ fn print<'a>(&'a self, cache: &'a Cache) -> impl fmt::Display + 'a {
display_fn(move |f| {
if !self.generic_params.is_empty() {
if f.alternate() {
write!(
f,
"for<{:#}> ",
- comma_sep(self.generic_params.iter().map(|g| g.print()))
+ comma_sep(self.generic_params.iter().map(|g| g.print(cache)))
)?;
} else {
write!(
f,
"for<{}> ",
- comma_sep(self.generic_params.iter().map(|g| g.print()))
+ comma_sep(self.generic_params.iter().map(|g| g.print(cache)))
)?;
}
}
if f.alternate() {
- write!(f, "{:#}", self.trait_.print())
+ write!(f, "{:#}", self.trait_.print(cache))
} else {
- write!(f, "{}", self.trait_.print())
+ write!(f, "{}", self.trait_.print(cache))
}
})
}
}
impl clean::GenericBound {
- crate fn print(&self) -> impl fmt::Display + '_ {
+ crate fn print<'a>(&'a self, cache: &'a Cache) -> impl fmt::Display + 'a {
display_fn(move |f| match self {
clean::GenericBound::Outlives(lt) => write!(f, "{}", lt.print()),
clean::GenericBound::TraitBound(ty, modifier) => {
@@ -364,9 +377,9 @@ impl clean::GenericBound {
hir::TraitBoundModifier::MaybeConst => "?const",
};
if f.alternate() {
- write!(f, "{}{:#}", modifier_str, ty.print())
+ write!(f, "{}{:#}", modifier_str, ty.print(cache))
} else {
- write!(f, "{}{}", modifier_str, ty.print())
+ write!(f, "{}{}", modifier_str, ty.print(cache))
}
}
})
@@ -374,7 +387,7 @@ impl clean::GenericBound {
}
impl clean::GenericArgs {
- fn print(&self) -> impl fmt::Display + '_ {
+ fn print<'a>(&'a self, cache: &'a Cache) -> impl fmt::Display + 'a {
display_fn(move |f| {
match self {
clean::GenericArgs::AngleBracketed { args, bindings } => {
@@ -391,9 +404,9 @@ impl clean::GenericArgs {
}
comma = true;
if f.alternate() {
- write!(f, "{:#}", arg.print())?;
+ write!(f, "{:#}", arg.print(cache))?;
} else {
- write!(f, "{}", arg.print())?;
+ write!(f, "{}", arg.print(cache))?;
}
}
for binding in bindings {
@@ -402,9 +415,9 @@ impl clean::GenericArgs {
}
comma = true;
if f.alternate() {
- write!(f, "{:#}", binding.print())?;
+ write!(f, "{:#}", binding.print(cache))?;
} else {
- write!(f, "{}", binding.print())?;
+ write!(f, "{}", binding.print(cache))?;
}
}
if f.alternate() {
@@ -423,17 +436,17 @@ impl clean::GenericArgs {
}
comma = true;
if f.alternate() {
- write!(f, "{:#}", ty.print())?;
+ write!(f, "{:#}", ty.print(cache))?;
} else {
- write!(f, "{}", ty.print())?;
+ write!(f, "{}", ty.print(cache))?;
}
}
f.write_str(")")?;
if let Some(ref ty) = *output {
if f.alternate() {
- write!(f, " -> {:#}", ty.print())?;
+ write!(f, " -> {:#}", ty.print(cache))?;
} else {
- write!(f, " -> {}", ty.print())?;
+ write!(f, " -> {}", ty.print(cache))?;
}
}
}
@@ -444,19 +457,19 @@ impl clean::GenericArgs {
}
impl clean::PathSegment {
- crate fn print(&self) -> impl fmt::Display + '_ {
+ crate fn print<'a>(&'a self, cache: &'a Cache) -> impl fmt::Display + 'a {
display_fn(move |f| {
if f.alternate() {
- write!(f, "{}{:#}", self.name, self.args.print())
+ write!(f, "{}{:#}", self.name, self.args.print(cache))
} else {
- write!(f, "{}{}", self.name, self.args.print())
+ write!(f, "{}{}", self.name, self.args.print(cache))
}
})
}
}
impl clean::Path {
- crate fn print(&self) -> impl fmt::Display + '_ {
+ crate fn print<'a>(&'a self, cache: &'a Cache) -> impl fmt::Display + 'a {
display_fn(move |f| {
if self.global {
f.write_str("::")?
@@ -467,9 +480,9 @@ impl clean::Path {
f.write_str("::")?
}
if f.alternate() {
- write!(f, "{:#}", seg.print())?;
+ write!(f, "{:#}", seg.print(cache))?;
} else {
- write!(f, "{}", seg.print())?;
+ write!(f, "{}", seg.print(cache))?;
}
}
Ok(())
@@ -477,8 +490,7 @@ impl clean::Path {
}
}
-crate fn href(did: DefId) -> Option<(String, ItemType, Vec");
@@ -1738,7 +1736,7 @@ fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer, cache: &Ca
// this page, and this link will be auto-clicked. The `id` attribute is
// used to find the link to auto-click.
if cx.shared.include_sources && !item.is_primitive() {
- write_srclink(cx, item, buf, cache);
+ write_srclink(cx, item, buf);
}
write!(buf, ""); // out-of-band
@@ -1797,20 +1795,20 @@ fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer, cache: &Ca
clean::FunctionItem(ref f) | clean::ForeignFunctionItem(ref f) => {
item_function(buf, cx, item, f)
}
- clean::TraitItem(ref t) => item_trait(buf, cx, item, t, cache),
- clean::StructItem(ref s) => item_struct(buf, cx, item, s, cache),
- clean::UnionItem(ref s) => item_union(buf, cx, item, s, cache),
- clean::EnumItem(ref e) => item_enum(buf, cx, item, e, cache),
- clean::TypedefItem(ref t, _) => item_typedef(buf, cx, item, t, cache),
+ clean::TraitItem(ref t) => item_trait(buf, cx, item, t),
+ clean::StructItem(ref s) => item_struct(buf, cx, item, s),
+ clean::UnionItem(ref s) => item_union(buf, cx, item, s),
+ clean::EnumItem(ref e) => item_enum(buf, cx, item, e),
+ clean::TypedefItem(ref t, _) => item_typedef(buf, cx, item, t),
clean::MacroItem(ref m) => item_macro(buf, cx, item, m),
clean::ProcMacroItem(ref m) => item_proc_macro(buf, cx, item, m),
- clean::PrimitiveItem(_) => item_primitive(buf, cx, item, cache),
+ clean::PrimitiveItem(_) => item_primitive(buf, cx, item),
clean::StaticItem(ref i) | clean::ForeignStaticItem(ref i) => item_static(buf, cx, item, i),
clean::ConstantItem(ref c) => item_constant(buf, cx, item, c),
- clean::ForeignTypeItem => item_foreign_type(buf, cx, item, cache),
+ clean::ForeignTypeItem => item_foreign_type(buf, cx, item),
clean::KeywordItem(_) => item_keyword(buf, cx, item),
- clean::OpaqueTyItem(ref e) => item_opaque_ty(buf, cx, item, e, cache),
- clean::TraitAliasItem(ref ta) => item_trait_alias(buf, cx, item, ta, cache),
+ clean::OpaqueTyItem(ref e) => item_opaque_ty(buf, cx, item, e),
+ clean::TraitAliasItem(ref ta) => item_trait_alias(buf, cx, item, ta),
_ => {
// We don't generate pages for any other type.
unreachable!();
@@ -1884,10 +1882,11 @@ fn document_short(
return;
}
if let Some(s) = item.doc_value() {
- let mut summary_html = MarkdownSummaryLine(&s, &item.links()).into_string();
+ let mut summary_html = MarkdownSummaryLine(&s, &item.links(&cx.cache)).into_string();
if s.contains('\n') {
- let link = format!(r#" Read more"#, naive_assoc_href(item, link));
+ let link =
+ format!(r#" Read more"#, naive_assoc_href(item, link, cx.cache()));
if let Some(idx) = summary_html.rfind("
{}extern crate {} as {};",
- myitem.visibility.print_with_space(cx.tcx(), myitem.def_id),
- anchor(myitem.def_id, &*src.as_str()),
+ myitem.visibility.print_with_space(cx.tcx(), myitem.def_id, cx.cache()),
+ anchor(myitem.def_id, &*src.as_str(), cx.cache()),
name
),
None => write!(
w,
"{}extern crate {};",
- myitem.visibility.print_with_space(cx.tcx(), myitem.def_id),
- anchor(myitem.def_id, &*name.as_str())
+ myitem.visibility.print_with_space(cx.tcx(), myitem.def_id, cx.cache()),
+ anchor(myitem.def_id, &*name.as_str(), cx.cache())
),
}
write!(w, " ");
@@ -2179,8 +2178,8 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
write!(
w,
"{}{} ",
- myitem.visibility.print_with_space(cx.tcx(), myitem.def_id),
- import.print()
+ myitem.visibility.print_with_space(cx.tcx(), myitem.def_id, cx.cache()),
+ import.print(cx.cache())
);
}
@@ -2211,7 +2210,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
");
@@ -2456,17 +2455,18 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::
w,
"{vis}{constness}{asyncness}{unsafety}{abi}fn \
{name}{generics}{decl}{spotlight}{where_clause}",
- vis = it.visibility.print_with_space(cx.tcx(), it.def_id),
+ vis = it.visibility.print_with_space(cx.tcx(), it.def_id, cx.cache()),
constness = f.header.constness.print_with_space(),
asyncness = f.header.asyncness.print_with_space(),
unsafety = f.header.unsafety.print_with_space(),
abi = print_abi_with_space(f.header.abi),
name = it.name.as_ref().unwrap(),
- generics = f.generics.print(),
- where_clause = WhereClause { gens: &f.generics, indent: 0, end_newline: true },
+ generics = f.generics.print(cx.cache()),
+ where_clause =
+ WhereClause { gens: &f.generics, indent: 0, end_newline: true }.print(cx.cache()),
decl = Function { decl: &f.decl, header_len, indent: 0, asyncness: f.header.asyncness }
- .print(),
- spotlight = spotlight_decl(&f.decl),
+ .print(cx.cache()),
+ spotlight = spotlight_decl(&f.decl, cx.cache()),
);
document(w, cx, it, None)
}
@@ -2478,7 +2478,6 @@ fn render_implementor(
w: &mut Buffer,
implementor_dups: &FxHashMap");
render_attributes(w, it, true);
@@ -3122,16 +3111,16 @@ fn item_struct(
item_type = ItemType::StructField,
id = id,
name = field.name.as_ref().unwrap(),
- ty = ty.print()
+ ty = ty.print(cx.cache())
);
document(w, cx, field, Some(it));
}
}
}
- render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All, cache)
+ render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)
}
-fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Union, cache: &Cache) {
+fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Union) {
wrap_into_docblock(w, |w| {
write!(w, "");
render_attributes(w, it, true);
@@ -3166,7 +3155,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
id = id,
name = name,
shortty = ItemType::StructField,
- ty = ty.print()
+ ty = ty.print(cx.cache())
);
if let Some(stability_class) = field.stability_class(cx.tcx()) {
write!(w, "", stab = stability_class);
@@ -3174,20 +3163,20 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
document(w, cx, field, Some(it));
}
}
- render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All, cache)
+ render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)
}
-fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum, cache: &Cache) {
+fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum) {
wrap_into_docblock(w, |w| {
write!(w, "");
render_attributes(w, it, true);
write!(
w,
"{}enum {}{}{}",
- it.visibility.print_with_space(cx.tcx(), it.def_id),
+ it.visibility.print_with_space(cx.tcx(), it.def_id, cx.cache()),
it.name.as_ref().unwrap(),
- e.generics.print(),
- WhereClause { gens: &e.generics, indent: 0, end_newline: true }
+ e.generics.print(cx.cache()),
+ WhereClause { gens: &e.generics, indent: 0, end_newline: true }.print(cx.cache())
);
if e.variants.is_empty() && !e.variants_stripped {
write!(w, " {{}}");
@@ -3205,7 +3194,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
if i > 0 {
write!(w, ", ")
}
- write!(w, "{}", ty.print());
+ write!(w, "{}", ty.print(cx.cache()));
}
write!(w, ")");
}
@@ -3252,7 +3241,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
if i > 0 {
write!(w, ", ");
}
- write!(w, "{}", ty.print());
+ write!(w, "{}", ty.print(cx.cache()));
}
write!(w, ")");
}
@@ -3289,7 +3278,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
",
id = id,
f = field.name.as_ref().unwrap(),
- t = ty.print()
+ t = ty.print(cx.cache())
);
document(w, cx, field, Some(variant));
}
@@ -3299,7 +3288,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
render_stability_since(w, variant, it, cx.tcx());
}
}
- render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All, cache)
+ render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)
}
const ALLOWED_ATTRIBUTES: &[Symbol] = &[
@@ -3357,17 +3346,21 @@ fn render_struct(
write!(
w,
"{}{}{}",
- it.visibility.print_with_space(cx.tcx(), it.def_id),
+ it.visibility.print_with_space(cx.tcx(), it.def_id, cx.cache()),
if structhead { "struct " } else { "" },
it.name.as_ref().unwrap()
);
if let Some(g) = g {
- write!(w, "{}", g.print())
+ write!(w, "{}", g.print(cx.cache()))
}
match ty {
CtorKind::Fictive => {
if let Some(g) = g {
- write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: true })
+ write!(
+ w,
+ "{}",
+ WhereClause { gens: g, indent: 0, end_newline: true }.print(cx.cache())
+ )
}
let mut has_visible_fields = false;
write!(w, " {{");
@@ -3377,9 +3370,9 @@ fn render_struct(
w,
"\n{} {}{}: {},",
tab,
- field.visibility.print_with_space(cx.tcx(), field.def_id),
+ field.visibility.print_with_space(cx.tcx(), field.def_id, cx.cache()),
field.name.as_ref().unwrap(),
- ty.print()
+ ty.print(cx.cache())
);
has_visible_fields = true;
}
@@ -3409,8 +3402,8 @@ fn render_struct(
write!(
w,
"{}{}",
- field.visibility.print_with_space(cx.tcx(), field.def_id),
- ty.print()
+ field.visibility.print_with_space(cx.tcx(), field.def_id, cx.cache()),
+ ty.print(cx.cache())
)
}
_ => unreachable!(),
@@ -3418,14 +3411,22 @@ fn render_struct(
}
write!(w, ")");
if let Some(g) = g {
- write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: false })
+ write!(
+ w,
+ "{}",
+ WhereClause { gens: g, indent: 0, end_newline: false }.print(cx.cache())
+ )
}
write!(w, ";");
}
CtorKind::Const => {
// Needed for PhantomData.
if let Some(g) = g {
- write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: false })
+ write!(
+ w,
+ "{}",
+ WhereClause { gens: g, indent: 0, end_newline: false }.print(cx.cache())
+ )
}
write!(w, ";");
}
@@ -3444,13 +3445,13 @@ fn render_union(
write!(
w,
"{}{}{}",
- it.visibility.print_with_space(cx.tcx(), it.def_id),
+ it.visibility.print_with_space(cx.tcx(), it.def_id, cx.cache()),
if structhead { "union " } else { "" },
it.name.as_ref().unwrap()
);
if let Some(g) = g {
- write!(w, "{}", g.print());
- write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: true });
+ write!(w, "{}", g.print(cx.cache()));
+ write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: true }.print(cx.cache()));
}
write!(w, " {{\n{}", tab);
@@ -3459,9 +3460,9 @@ fn render_union(
write!(
w,
" {}{}: {},\n{}",
- field.visibility.print_with_space(cx.tcx(), field.def_id),
+ field.visibility.print_with_space(cx.tcx(), field.def_id, cx.cache()),
field.name.as_ref().unwrap(),
- ty.print(),
+ ty.print(cx.cache()),
tab
);
}
@@ -3494,10 +3495,9 @@ fn render_assoc_items(
containing_item: &clean::Item,
it: DefId,
what: AssocItemRender<'_>,
- cache: &Cache,
) {
info!("Documenting associated items of {:?}", containing_item.name);
- let v = match cache.impls.get(&it) {
+ let v = match cx.cache.impls.get(&it) {
Some(v) => v,
None => return,
};
@@ -3514,9 +3514,13 @@ fn render_assoc_items(
RenderMode::Normal
}
AssocItemRender::DerefFor { trait_, type_, deref_mut_ } => {
- let id =
- cx.derive_id(small_url_encode(&format!("deref-methods-{:#}", type_.print())));
- cx.deref_id_map.borrow_mut().insert(type_.def_id().unwrap(), id.clone());
+ let id = cx.derive_id(small_url_encode(&format!(
+ "deref-methods-{:#}",
+ type_.print(cx.cache())
+ )));
+ cx.deref_id_map
+ .borrow_mut()
+ .insert(type_.def_id_full(cx.cache()).unwrap(), id.clone());
write!(
w,
"\
@@ -3524,8 +3528,8 @@ fn render_assoc_items(
\
",
id = id,
- trait_ = trait_.print(),
- type_ = type_.print(),
+ trait_ = trait_.print(cx.cache()),
+ type_ = type_.print(cx.cache()),
);
RenderMode::ForDeref { mut_: deref_mut_ }
}
@@ -3545,17 +3549,18 @@ fn render_assoc_items(
false,
true,
&[],
- cache,
);
}
}
if !traits.is_empty() {
- let deref_impl =
- traits.iter().find(|t| t.inner_impl().trait_.def_id() == cache.deref_trait_did);
+ let deref_impl = traits
+ .iter()
+ .find(|t| t.inner_impl().trait_.def_id_full(cx.cache()) == cx.cache.deref_trait_did);
if let Some(impl_) = deref_impl {
- let has_deref_mut =
- traits.iter().any(|t| t.inner_impl().trait_.def_id() == cache.deref_mut_trait_did);
- render_deref_methods(w, cx, impl_, containing_item, has_deref_mut, cache);
+ let has_deref_mut = traits.iter().any(|t| {
+ t.inner_impl().trait_.def_id_full(cx.cache()) == cx.cache.deref_mut_trait_did
+ });
+ render_deref_methods(w, cx, impl_, containing_item, has_deref_mut);
}
// If we were already one level into rendering deref methods, we don't want to render
@@ -3570,7 +3575,7 @@ fn render_assoc_items(
concrete.into_iter().partition(|t| t.inner_impl().blanket_impl.is_some());
let mut impls = Buffer::empty_from(&w);
- render_impls(cx, &mut impls, &concrete, containing_item, cache);
+ render_impls(cx, &mut impls, &concrete, containing_item);
let impls = impls.into_inner();
if !impls.is_empty() {
write!(
@@ -3592,7 +3597,7 @@ fn render_assoc_items(
\
"
);
- render_impls(cx, w, &synthetic, containing_item, cache);
+ render_impls(cx, w, &synthetic, containing_item);
write!(w, "");
}
@@ -3605,7 +3610,7 @@ fn render_assoc_items(
\
"
);
- render_impls(cx, w, &blanket_impl, containing_item, cache);
+ render_impls(cx, w, &blanket_impl, containing_item);
write!(w, "");
}
}
@@ -3617,7 +3622,6 @@ fn render_deref_methods(
impl_: &Impl,
container_item: &clean::Item,
deref_mut: bool,
- cache: &Cache,
) {
let deref_type = impl_.inner_impl().trait_.as_ref().unwrap();
let (target, real_target) = impl_
@@ -3634,25 +3638,25 @@ fn render_deref_methods(
.expect("Expected associated type binding");
let what =
AssocItemRender::DerefFor { trait_: deref_type, type_: real_target, deref_mut_: deref_mut };
- if let Some(did) = target.def_id() {
- if let Some(type_did) = impl_.inner_impl().for_.def_id() {
+ if let Some(did) = target.def_id_full(cx.cache()) {
+ if let Some(type_did) = impl_.inner_impl().for_.def_id_full(cx.cache()) {
// `impl Deref for S`
if did == type_did {
// Avoid infinite cycles
return;
}
}
- render_assoc_items(w, cx, container_item, did, what, cache);
+ render_assoc_items(w, cx, container_item, did, what);
} else {
if let Some(prim) = target.primitive_type() {
- if let Some(&did) = cache.primitive_locations.get(&prim) {
- render_assoc_items(w, cx, container_item, did, what, cache);
+ if let Some(&did) = cx.cache.primitive_locations.get(&prim) {
+ render_assoc_items(w, cx, container_item, did, what);
}
}
}
}
-fn should_render_item(item: &clean::Item, deref_mut_: bool) -> bool {
+fn should_render_item(item: &clean::Item, deref_mut_: bool, cache: &Cache) -> bool {
let self_type_opt = match *item.kind {
clean::MethodItem(ref method, _) => method.decl.self_type(),
clean::TyMethodItem(ref method) => method.decl.self_type(),
@@ -3666,7 +3670,7 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool) -> bool {
(mutability == Mutability::Mut, false, false)
}
SelfTy::SelfExplicit(clean::ResolvedPath { did, .. }) => {
- (false, Some(did) == cache().owned_box_did, false)
+ (false, Some(did) == cache.owned_box_did, false)
}
SelfTy::SelfValue => (false, false, true),
_ => (false, false, false),
@@ -3678,31 +3682,31 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool) -> bool {
}
}
-fn spotlight_decl(decl: &clean::FnDecl) -> String {
+fn spotlight_decl(decl: &clean::FnDecl, cache: &Cache) -> String {
let mut out = Buffer::html();
let mut trait_ = String::new();
- if let Some(did) = decl.output.def_id() {
- let c = cache();
- if let Some(impls) = c.impls.get(&did) {
+ if let Some(did) = decl.output.def_id_full(cache) {
+ if let Some(impls) = cache.impls.get(&did) {
for i in impls {
let impl_ = i.inner_impl();
- if impl_.trait_.def_id().map_or(false, |d| c.traits[&d].is_spotlight) {
+ if impl_.trait_.def_id_full(cache).map_or(false, |d| cache.traits[&d].is_spotlight)
+ {
if out.is_empty() {
out.push_str(&format!(
"Notable traits for {}
\
",
- impl_.for_.print()
+ impl_.for_.print(cache)
));
- trait_.push_str(&impl_.for_.print().to_string());
+ trait_.push_str(&impl_.for_.print(cache).to_string());
}
//use the "where" class here to make it small
out.push_str(&format!(
"{}",
- impl_.print()
+ impl_.print(cache)
));
- let t_did = impl_.trait_.def_id().unwrap();
+ let t_did = impl_.trait_.def_id_full(cache).unwrap();
for it in &impl_.items {
if let clean::TypedefItem(ref tydef, _) = *it.kind {
out.push_str(" ");
@@ -3713,6 +3717,7 @@ fn spotlight_decl(decl: &clean::FnDecl) -> String {
Some(&tydef.type_),
AssocItemLink::GotoSource(t_did, &FxHashSet::default()),
"",
+ cache,
);
out.push_str(";");
}
@@ -3750,18 +3755,17 @@ fn render_impl(
// This argument is used to reference same type with different paths to avoid duplication
// in documentation pages for trait with automatic implementations like "Send" and "Sync".
aliases: &[String],
- cache: &Cache,
) {
- let traits = &cache.traits;
- let trait_ = i.trait_did().map(|did| &traits[&did]);
+ let traits = &cx.cache.traits;
+ let trait_ = i.trait_did_full(cx.cache()).map(|did| &traits[&did]);
if render_mode == RenderMode::Normal {
let id = cx.derive_id(match i.inner_impl().trait_ {
Some(ref t) => {
if is_on_foreign_type {
- get_id_for_impl_on_foreign_type(&i.inner_impl().for_, t)
+ get_id_for_impl_on_foreign_type(&i.inner_impl().for_, t, cx.cache())
} else {
- format!("impl-{}", small_url_encode(&format!("{:#}", t.print())))
+ format!("impl-{}", small_url_encode(&format!("{:#}", t.print(cx.cache()))))
}
}
None => "impl".to_string(),
@@ -3773,12 +3777,20 @@ fn render_impl(
};
if let Some(use_absolute) = use_absolute {
write!(w, "", id, aliases);
- fmt_impl_for_trait_page(&i.inner_impl(), w, use_absolute);
+ fmt_impl_for_trait_page(&i.inner_impl(), w, use_absolute, cx.cache());
if show_def_docs {
for it in &i.inner_impl().items {
if let clean::TypedefItem(ref tydef, _) = *it.kind {
write!(w, " ");
- assoc_type(w, it, &[], Some(&tydef.type_), AssocItemLink::Anchor(None), "");
+ assoc_type(
+ w,
+ it,
+ &[],
+ Some(&tydef.type_),
+ AssocItemLink::Anchor(None),
+ "",
+ cx.cache(),
+ );
write!(w, ";");
}
}
@@ -3790,7 +3802,7 @@ fn render_impl(
"{}",
id,
aliases,
- i.inner_impl().print()
+ i.inner_impl().print(cx.cache())
);
}
write!(w, "", id);
@@ -3801,7 +3813,7 @@ fn render_impl(
outer_version,
outer_const_version,
);
- write_srclink(cx, &i.impl_item, w, cache);
+ write_srclink(cx, &i.impl_item, w);
write!(w, "
");
if trait_.is_some() {
@@ -3817,7 +3829,7 @@ fn render_impl(
"{}",
Markdown(
&*dox,
- &i.impl_item.links(),
+ &i.impl_item.links(&cx.cache),
&mut ids,
cx.shared.codes,
cx.shared.edition,
@@ -3840,14 +3852,15 @@ fn render_impl(
outer_const_version: Option<&str>,
trait_: Option<&clean::Trait>,
show_def_docs: bool,
- cache: &Cache,
) {
let item_type = item.type_();
let name = item.name.as_ref().unwrap();
let render_method_item = match render_mode {
RenderMode::Normal => true,
- RenderMode::ForDeref { mut_: deref_mut_ } => should_render_item(&item, deref_mut_),
+ RenderMode::ForDeref { mut_: deref_mut_ } => {
+ should_render_item(&item, deref_mut_, &cx.cache)
+ }
};
let (is_hidden, extra_class) =
@@ -3874,14 +3887,22 @@ fn render_impl(
outer_version,
outer_const_version,
);
- write_srclink(cx, item, w, cache);
+ write_srclink(cx, item, w);
write!(w, "");
}
}
clean::TypedefItem(ref tydef, _) => {
let id = cx.derive_id(format!("{}.{}", ItemType::AssocType, name));
write!(w, "", id, item_type, extra_class);
- assoc_type(w, item, &Vec::new(), Some(&tydef.type_), link.anchor(&id), "");
+ assoc_type(
+ w,
+ item,
+ &Vec::new(),
+ Some(&tydef.type_),
+ link.anchor(&id),
+ "",
+ cx.cache(),
+ );
write!(w, "
");
}
clean::AssocConstItem(ref ty, ref default) => {
@@ -3896,13 +3917,13 @@ fn render_impl(
outer_version,
outer_const_version,
);
- write_srclink(cx, item, w, cache);
+ write_srclink(cx, item, w);
write!(w, "");
}
clean::AssocTypeItem(ref bounds, ref default) => {
let id = cx.derive_id(format!("{}.{}", item_type, name));
write!(w, "", id, item_type, extra_class);
- assoc_type(w, item, bounds, default.as_ref(), link.anchor(&id), "");
+ assoc_type(w, item, bounds, default.as_ref(), link.anchor(&id), "", cx.cache());
write!(w, "
");
}
clean::StrippedItem(..) => return,
@@ -3961,7 +3982,6 @@ fn render_impl(
outer_const_version,
trait_,
show_def_docs,
- cache,
);
}
@@ -3975,14 +3995,13 @@ fn render_impl(
outer_version: Option<&str>,
outer_const_version: Option<&str>,
show_def_docs: bool,
- cache: &Cache,
) {
for trait_item in &t.items {
let n = trait_item.name;
if i.items.iter().any(|m| m.name == n) {
continue;
}
- let did = i.trait_.as_ref().unwrap().def_id().unwrap();
+ let did = i.trait_.as_ref().unwrap().def_id_full(cx.cache()).unwrap();
let assoc_link = AssocItemLink::GotoSource(did, &i.provided_trait_methods);
doc_impl_item(
@@ -3997,7 +4016,6 @@ fn render_impl(
outer_const_version,
None,
show_def_docs,
- cache,
);
}
}
@@ -4018,29 +4036,23 @@ fn render_impl(
outer_version,
outer_const_version,
show_def_docs,
- cache,
);
}
}
write!(w, "");
}
-fn item_opaque_ty(
- w: &mut Buffer,
- cx: &Context<'_>,
- it: &clean::Item,
- t: &clean::OpaqueTy,
- cache: &Cache,
-) {
+fn item_opaque_ty(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::OpaqueTy) {
write!(w, "");
render_attributes(w, it, false);
write!(
w,
"type {}{}{where_clause} = impl {bounds};",
it.name.as_ref().unwrap(),
- t.generics.print(),
- where_clause = WhereClause { gens: &t.generics, indent: 0, end_newline: true },
- bounds = bounds(&t.bounds, false)
+ t.generics.print(cx.cache()),
+ where_clause =
+ WhereClause { gens: &t.generics, indent: 0, end_newline: true }.print(cx.cache()),
+ bounds = bounds(&t.bounds, false, cx.cache())
);
document(w, cx, it, None);
@@ -4049,25 +4061,19 @@ fn item_opaque_ty(
// won't be visible anywhere in the docs. It would be nice to also show
// associated items from the aliased type (see discussion in #32077), but
// we need #14072 to make sense of the generics.
- render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All, cache)
+ render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)
}
-fn item_trait_alias(
- w: &mut Buffer,
- cx: &Context<'_>,
- it: &clean::Item,
- t: &clean::TraitAlias,
- cache: &Cache,
-) {
+fn item_trait_alias(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::TraitAlias) {
write!(w, "");
render_attributes(w, it, false);
write!(
w,
"trait {}{}{} = {};",
it.name.as_ref().unwrap(),
- t.generics.print(),
- WhereClause { gens: &t.generics, indent: 0, end_newline: true },
- bounds(&t.bounds, true)
+ t.generics.print(cx.cache()),
+ WhereClause { gens: &t.generics, indent: 0, end_newline: true }.print(cx.cache()),
+ bounds(&t.bounds, true, cx.cache())
);
document(w, cx, it, None);
@@ -4076,25 +4082,20 @@ fn item_trait_alias(
// won't be visible anywhere in the docs. It would be nice to also show
// associated items from the aliased type (see discussion in #32077), but
// we need #14072 to make sense of the generics.
- render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All, cache)
+ render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)
}
-fn item_typedef(
- w: &mut Buffer,
- cx: &Context<'_>,
- it: &clean::Item,
- t: &clean::Typedef,
- cache: &Cache,
-) {
+fn item_typedef(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Typedef) {
write!(w, "");
render_attributes(w, it, false);
write!(
w,
"type {}{}{where_clause} = {type_};",
it.name.as_ref().unwrap(),
- t.generics.print(),
- where_clause = WhereClause { gens: &t.generics, indent: 0, end_newline: true },
- type_ = t.type_.print()
+ t.generics.print(cx.cache()),
+ where_clause =
+ WhereClause { gens: &t.generics, indent: 0, end_newline: true }.print(cx.cache()),
+ type_ = t.type_.print(cx.cache())
);
document(w, cx, it, None);
@@ -4103,25 +4104,25 @@ fn item_typedef(
// won't be visible anywhere in the docs. It would be nice to also show
// associated items from the aliased type (see discussion in #32077), but
// we need #14072 to make sense of the generics.
- render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All, cache)
+ render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)
}
-fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, cache: &Cache) {
+fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
writeln!(w, "extern {{");
render_attributes(w, it, false);
write!(
w,
" {}type {};\n}}",
- it.visibility.print_with_space(cx.tcx(), it.def_id),
+ it.visibility.print_with_space(cx.tcx(), it.def_id, cx.cache()),
it.name.as_ref().unwrap(),
);
document(w, cx, it, None);
- render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All, cache)
+ render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)
}
-fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer, cache: &Cache) {
+fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
let parentlen = cx.current.len() - if it.is_mod() { 1 } else { 0 };
if it.is_struct()
@@ -4156,7 +4157,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer, cache:
}
if it.is_crate() {
- if let Some(ref version) = cache.crate_version {
+ if let Some(ref version) = cx.cache.crate_version {
write!(
buffer,
"\
@@ -4245,12 +4246,13 @@ fn get_methods(
for_deref: bool,
used_links: &mut FxHashSet,
deref_mut: bool,
+ cache: &Cache,
) -> Vec {
i.items
.iter()
.filter_map(|item| match item.name {
Some(ref name) if !name.is_empty() && item.is_method() => {
- if !for_deref || should_render_item(item, deref_mut) {
+ if !for_deref || should_render_item(item, deref_mut, cache) {
Some(format!(
"{}",
get_next_url(used_links, format!("method.{}", name)),
@@ -4283,8 +4285,7 @@ fn small_url_encode(s: &str) -> String {
fn sidebar_assoc_items(cx: &Context<'_>, it: &clean::Item) -> String {
let mut out = String::new();
- let c = cache();
- if let Some(v) = c.impls.get(&it.def_id) {
+ if let Some(v) = cx.cache.impls.get(&it.def_id) {
let mut used_links = FxHashSet::default();
{
@@ -4292,7 +4293,9 @@ fn sidebar_assoc_items(cx: &Context<'_>, it: &clean::Item) -> String {
let mut ret = v
.iter()
.filter(|i| i.inner_impl().trait_.is_none())
- .flat_map(move |i| get_methods(i.inner_impl(), false, used_links_bor, false))
+ .flat_map(move |i| {
+ get_methods(i.inner_impl(), false, used_links_bor, false, &cx.cache)
+ })
.collect::>();
if !ret.is_empty() {
// We want links' order to be reproducible so we don't use unstable sort.
@@ -4309,7 +4312,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, it: &clean::Item) -> String {
if let Some(impl_) = v
.iter()
.filter(|i| i.inner_impl().trait_.is_some())
- .find(|i| i.inner_impl().trait_.def_id() == c.deref_trait_did)
+ .find(|i| i.inner_impl().trait_.def_id_full(cx.cache()) == cx.cache.deref_trait_did)
{
out.push_str(&sidebar_deref_methods(cx, impl_, v));
}
@@ -4320,9 +4323,9 @@ fn sidebar_assoc_items(cx: &Context<'_>, it: &clean::Item) -> String {
.iter()
.filter_map(|it| {
if let Some(ref i) = it.inner_impl().trait_ {
- let i_display = format!("{:#}", i.print());
+ let i_display = format!("{:#}", i.print(cx.cache()));
let out = Escape(&i_display);
- let encoded = small_url_encode(&format!("{:#}", i.print()));
+ let encoded = small_url_encode(&format!("{:#}", i.print(cx.cache())));
let generated = format!(
"{}{}",
encoded,
@@ -4380,7 +4383,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, it: &clean::Item) -> String {
fn sidebar_deref_methods(cx: &Context<'_>, impl_: &Impl, v: &Vec) -> String {
let mut out = String::new();
- let c = cache();
+ let c = cx.cache();
debug!("found Deref: {:?}", impl_);
if let Some((target, real_target)) =
@@ -4396,9 +4399,9 @@ fn sidebar_deref_methods(cx: &Context<'_>, impl_: &Impl, v: &Vec) -> Strin
let deref_mut = v
.iter()
.filter(|i| i.inner_impl().trait_.is_some())
- .any(|i| i.inner_impl().trait_.def_id() == c.deref_mut_trait_did);
+ .any(|i| i.inner_impl().trait_.def_id_full(cx.cache()) == c.deref_mut_trait_did);
let inner_impl = target
- .def_id()
+ .def_id_full(cx.cache())
.or_else(|| {
target.primitive_type().and_then(|prim| c.primitive_locations.get(&prim).cloned())
})
@@ -4409,18 +4412,18 @@ fn sidebar_deref_methods(cx: &Context<'_>, impl_: &Impl, v: &Vec) -> Strin
let mut ret = impls
.iter()
.filter(|i| i.inner_impl().trait_.is_none())
- .flat_map(|i| get_methods(i.inner_impl(), true, &mut used_links, deref_mut))
+ .flat_map(|i| get_methods(i.inner_impl(), true, &mut used_links, deref_mut, c))
.collect::>();
if !ret.is_empty() {
let deref_id_map = cx.deref_id_map.borrow();
let id = deref_id_map
- .get(&real_target.def_id().unwrap())
+ .get(&real_target.def_id_full(cx.cache()).unwrap())
.expect("Deref section without derived id");
out.push_str(&format!(
"Methods from {}<Target={}>",
id,
- Escape(&format!("{:#}", impl_.inner_impl().trait_.as_ref().unwrap().print())),
- Escape(&format!("{:#}", real_target.print())),
+ Escape(&format!("{:#}", impl_.inner_impl().trait_.as_ref().unwrap().print(c))),
+ Escape(&format!("{:#}", real_target.print(c))),
));
// We want links' order to be reproducible so we don't use unstable sort.
ret.sort();
@@ -4429,14 +4432,14 @@ fn sidebar_deref_methods(cx: &Context<'_>, impl_: &Impl, v: &Vec) -> Strin
}
// Recurse into any further impls that might exist for `target`
- if let Some(target_did) = target.def_id() {
+ if let Some(target_did) = target.def_id_full(cx.cache()) {
if let Some(target_impls) = c.impls.get(&target_did) {
if let Some(target_deref_impl) = target_impls
.iter()
.filter(|i| i.inner_impl().trait_.is_some())
- .find(|i| i.inner_impl().trait_.def_id() == c.deref_trait_did)
+ .find(|i| i.inner_impl().trait_.def_id_full(cx.cache()) == c.deref_trait_did)
{
- if let Some(type_did) = impl_.inner_impl().for_.def_id() {
+ if let Some(type_did) = impl_.inner_impl().for_.def_id_full(cx.cache()) {
// `impl Deref for S`
if target_did == type_did {
// Avoid infinite cycles
@@ -4473,17 +4476,21 @@ fn sidebar_struct(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, s: &clea
}
}
-fn get_id_for_impl_on_foreign_type(for_: &clean::Type, trait_: &clean::Type) -> String {
- small_url_encode(&format!("impl-{:#}-for-{:#}", trait_.print(), for_.print()))
+fn get_id_for_impl_on_foreign_type(
+ for_: &clean::Type,
+ trait_: &clean::Type,
+ cache: &Cache,
+) -> String {
+ small_url_encode(&format!("impl-{:#}-for-{:#}", trait_.print(cache), for_.print(cache)))
}
-fn extract_for_impl_name(item: &clean::Item) -> Option<(String, String)> {
+fn extract_for_impl_name(item: &clean::Item, cache: &Cache) -> Option<(String, String)> {
match *item.kind {
clean::ItemKind::ImplItem(ref i) => {
if let Some(ref trait_) = i.trait_ {
Some((
- format!("{:#}", i.for_.print()),
- get_id_for_impl_on_foreign_type(&i.for_, trait_),
+ format!("{:#}", i.for_.print(cache)),
+ get_id_for_impl_on_foreign_type(&i.for_, trait_, cache),
))
} else {
None
@@ -4570,13 +4577,16 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
));
}
- let c = cache();
-
- if let Some(implementors) = c.implementors.get(&it.def_id) {
+ if let Some(implementors) = cx.cache.implementors.get(&it.def_id) {
let mut res = implementors
.iter()
- .filter(|i| i.inner_impl().for_.def_id().map_or(false, |d| !c.paths.contains_key(&d)))
- .filter_map(|i| extract_for_impl_name(&i.impl_item))
+ .filter(|i| {
+ i.inner_impl()
+ .for_
+ .def_id_full(cx.cache())
+ .map_or(false, |d| !cx.cache.paths.contains_key(&d))
+ })
+ .filter_map(|i| extract_for_impl_name(&i.impl_item, cx.cache()))
.collect::>();
if !res.is_empty() {
@@ -4815,9 +4825,9 @@ fn item_proc_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, m: &clean
document(w, cx, it, None)
}
-fn item_primitive(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, cache: &Cache) {
+fn item_primitive(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
document(w, cx, it, None);
- render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All, cache)
+ render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)
}
fn item_keyword(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
@@ -4836,11 +4846,10 @@ fn make_item_keywords(it: &clean::Item) -> String {
/// types are re-exported, we don't use the corresponding
/// entry from the js file, as inlining will have already
/// picked up the impl
-fn collect_paths_for_type(first_ty: clean::Type) -> Vec {
+fn collect_paths_for_type(first_ty: clean::Type, cache: &Cache) -> Vec {
let mut out = Vec::new();
let mut visited = FxHashSet::default();
let mut work = VecDeque::new();
- let cache = cache();
work.push_back(first_ty);
diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs
index 512c9124727ef..a8a4b74b818b6 100644
--- a/src/librustdoc/json/mod.rs
+++ b/src/librustdoc/json/mod.rs
@@ -32,6 +32,7 @@ crate struct JsonRenderer<'tcx> {
index: Rc>>,
/// The directory where the blob will be written to.
out_path: PathBuf,
+ cache: Rc,
}
impl JsonRenderer<'_> {
@@ -39,12 +40,8 @@ impl JsonRenderer<'_> {
self.tcx.sess
}
- fn get_trait_implementors(
- &mut self,
- id: rustc_span::def_id::DefId,
- cache: &Cache,
- ) -> Vec {
- cache
+ fn get_trait_implementors(&mut self, id: rustc_span::def_id::DefId) -> Vec {
+ Rc::clone(&self.cache)
.implementors
.get(&id)
.map(|implementors| {
@@ -52,7 +49,7 @@ impl JsonRenderer<'_> {
.iter()
.map(|i| {
let item = &i.impl_item;
- self.item(item.clone(), cache).unwrap();
+ self.item(item.clone()).unwrap();
item.def_id.into()
})
.collect()
@@ -60,8 +57,8 @@ impl JsonRenderer<'_> {
.unwrap_or_default()
}
- fn get_impls(&mut self, id: rustc_span::def_id::DefId, cache: &Cache) -> Vec {
- cache
+ fn get_impls(&mut self, id: rustc_span::def_id::DefId) -> Vec {
+ Rc::clone(&self.cache)
.impls
.get(&id)
.map(|impls| {
@@ -70,7 +67,7 @@ impl JsonRenderer<'_> {
.filter_map(|i| {
let item = &i.impl_item;
if item.def_id.is_local() {
- self.item(item.clone(), cache).unwrap();
+ self.item(item.clone()).unwrap();
Some(item.def_id.into())
} else {
None
@@ -81,24 +78,25 @@ impl JsonRenderer<'_> {
.unwrap_or_default()
}
- fn get_trait_items(&mut self, cache: &Cache) -> Vec<(types::Id, types::Item)> {
- cache
+ fn get_trait_items(&mut self) -> Vec<(types::Id, types::Item)> {
+ Rc::clone(&self.cache)
.traits
.iter()
.filter_map(|(&id, trait_item)| {
// only need to synthesize items for external traits
if !id.is_local() {
- trait_item.items.clone().into_iter().for_each(|i| self.item(i, cache).unwrap());
+ trait_item.items.clone().into_iter().for_each(|i| self.item(i).unwrap());
Some((
id.into(),
types::Item {
id: id.into(),
crate_id: id.krate.as_u32(),
- name: cache
+ name: self
+ .cache
.paths
.get(&id)
.unwrap_or_else(|| {
- cache
+ self.cache
.external_paths
.get(&id)
.expect("Trait should either be in local or external paths")
@@ -134,7 +132,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
options: RenderOptions,
_render_info: RenderInfo,
_edition: Edition,
- _cache: &mut Cache,
+ cache: Cache,
tcx: TyCtxt<'tcx>,
) -> Result<(Self, clean::Crate), Error> {
debug!("Initializing json renderer");
@@ -143,6 +141,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
tcx,
index: Rc::new(RefCell::new(FxHashMap::default())),
out_path: options.output,
+ cache: Rc::new(cache),
},
krate,
))
@@ -151,18 +150,18 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
/// Inserts an item into the index. This should be used rather than directly calling insert on
/// the hashmap because certain items (traits and types) need to have their mappings for trait
/// implementations filled out before they're inserted.
- fn item(&mut self, item: clean::Item, cache: &Cache) -> Result<(), Error> {
+ fn item(&mut self, item: clean::Item) -> Result<(), Error> {
// Flatten items that recursively store other items
- item.kind.inner_items().for_each(|i| self.item(i.clone(), cache).unwrap());
+ item.kind.inner_items().for_each(|i| self.item(i.clone()).unwrap());
let id = item.def_id;
if let Some(mut new_item) = self.convert_item(item) {
if let types::ItemEnum::TraitItem(ref mut t) = new_item.inner {
- t.implementors = self.get_trait_implementors(id, cache)
+ t.implementors = self.get_trait_implementors(id)
} else if let types::ItemEnum::StructItem(ref mut s) = new_item.inner {
- s.impls = self.get_impls(id, cache)
+ s.impls = self.get_impls(id)
} else if let types::ItemEnum::EnumItem(ref mut e) = new_item.inner {
- e.impls = self.get_impls(id, cache)
+ e.impls = self.get_impls(id)
}
let removed = self.index.borrow_mut().insert(id.into(), new_item.clone());
// FIXME(adotinthevoid): Currently, the index is duplicated. This is a sanity check
@@ -175,27 +174,20 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
Ok(())
}
- fn mod_item_in(
- &mut self,
- item: &clean::Item,
- _module_name: &str,
- cache: &Cache,
- ) -> Result<(), Error> {
+ fn mod_item_in(&mut self, item: &clean::Item, _module_name: &str) -> Result<(), Error> {
use clean::types::ItemKind::*;
if let ModuleItem(m) = &*item.kind {
for item in &m.items {
match &*item.kind {
// These don't have names so they don't get added to the output by default
- ImportItem(_) => self.item(item.clone(), cache).unwrap(),
- ExternCrateItem(_, _) => self.item(item.clone(), cache).unwrap(),
- ImplItem(i) => {
- i.items.iter().for_each(|i| self.item(i.clone(), cache).unwrap())
- }
+ ImportItem(_) => self.item(item.clone()).unwrap(),
+ ExternCrateItem(_, _) => self.item(item.clone()).unwrap(),
+ ImplItem(i) => i.items.iter().for_each(|i| self.item(i.clone()).unwrap()),
_ => {}
}
}
}
- self.item(item.clone(), cache).unwrap();
+ self.item(item.clone()).unwrap();
Ok(())
}
@@ -206,22 +198,22 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
fn after_krate(
&mut self,
krate: &clean::Crate,
- cache: &Cache,
_diag: &rustc_errors::Handler,
) -> Result<(), Error> {
debug!("Done with crate");
let mut index = (*self.index).clone().into_inner();
- index.extend(self.get_trait_items(cache));
+ index.extend(self.get_trait_items());
let output = types::Crate {
root: types::Id(String::from("0:0")),
crate_version: krate.version.clone(),
- includes_private: cache.document_private,
+ includes_private: self.cache.document_private,
index,
- paths: cache
+ paths: self
+ .cache
.paths
.clone()
.into_iter()
- .chain(cache.external_paths.clone().into_iter())
+ .chain(self.cache.external_paths.clone().into_iter())
.map(|(k, (path, kind))| {
(
k.into(),
@@ -229,7 +221,8 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
)
})
.collect(),
- external_crates: cache
+ external_crates: self
+ .cache
.extern_locations
.iter()
.map(|(k, v)| {
@@ -254,4 +247,8 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
serde_json::ser::to_writer(&file, &output).unwrap();
Ok(())
}
+
+ fn cache(&self) -> &Cache {
+ &self.cache
+ }
}
diff --git a/src/librustdoc/passes/calculate_doc_coverage.rs b/src/librustdoc/passes/calculate_doc_coverage.rs
index 05a3a15adac80..61e14c0522277 100644
--- a/src/librustdoc/passes/calculate_doc_coverage.rs
+++ b/src/librustdoc/passes/calculate_doc_coverage.rs
@@ -218,7 +218,12 @@ impl<'a, 'b> fold::DocFolder for CoverageCalculator<'a, 'b> {
clean::ImplItem(ref impl_) => {
let filename = i.source.filename(self.ctx.sess());
if let Some(ref tr) = impl_.trait_ {
- debug!("impl {:#} for {:#} in {}", tr.print(), impl_.for_.print(), filename,);
+ debug!(
+ "impl {:#} for {:#} in {}",
+ tr.print(&self.ctx.cache),
+ impl_.for_.print(&self.ctx.cache),
+ filename,
+ );
// don't count trait impls, the missing-docs lint doesn't so we shouldn't
// either
@@ -227,7 +232,7 @@ impl<'a, 'b> fold::DocFolder for CoverageCalculator<'a, 'b> {
// inherent impls *can* be documented, and those docs show up, but in most
// cases it doesn't make sense, as all methods on a type are in one single
// impl block
- debug!("impl {:#} in {}", impl_.for_.print(), filename);
+ debug!("impl {:#} in {}", impl_.for_.print(&self.ctx.cache), filename);
}
}
_ => {
diff --git a/src/test/rustdoc-js-std/primitive.js b/src/test/rustdoc-js-std/primitive.js
new file mode 100644
index 0000000000000..e5690383e4f0b
--- /dev/null
+++ b/src/test/rustdoc-js-std/primitive.js
@@ -0,0 +1,75 @@
+const QUERY = [
+ 'i8',
+ 'u32',
+ 'str',
+ 'char',
+ 'unit',
+ 'tuple',
+ 'fn',
+];
+
+const EXPECTED = [
+ {
+ 'others': [
+ {
+ 'path': 'std',
+ 'name': 'i8',
+ 'href': '../std/primitive.i8.html',
+ },
+ ]
+ },
+ {
+ 'others': [
+ {
+ 'path': 'std',
+ 'name': 'u32',
+ 'href': '../std/primitive.u32.html',
+ },
+ ]
+ },
+ {
+ 'others': [
+ {
+ 'path': 'std',
+ 'name': 'str',
+ 'href': '../std/primitive.str.html',
+ },
+ ]
+ },
+ {
+ 'others': [
+ {
+ 'path': 'std',
+ 'name': 'char',
+ 'href': '../std/primitive.char.html',
+ },
+ ]
+ },
+ {
+ 'others': [
+ {
+ 'path': 'std',
+ 'name': 'unit',
+ 'href': '../std/primitive.unit.html',
+ },
+ ]
+ },
+ {
+ 'others': [
+ {
+ 'path': 'std',
+ 'name': 'tuple',
+ 'href': '../std/primitive.tuple.html',
+ },
+ ]
+ },
+ {
+ 'others': [
+ {
+ 'path': 'std',
+ 'name': 'fn',
+ 'href': '../std/primitive.fn.html',
+ },
+ ]
+ },
+];