playground: Option<markdown::Playground>,
}
-impl Context<'_> {
+impl<'tcx> Context<'tcx> {
fn path(&self, filename: &str) -> PathBuf {
// We use splitn vs Path::extension here because we might get a filename
// like `style.min.css` and we want to process that into
self.dst.join(&filename)
}
+ fn tcx(&self) -> TyCtxt<'tcx> {
+ self.shared.tcx
+ }
+
fn sess(&self) -> &Session {
&self.shared.tcx.sess
}
Some(ref src) => write!(
w,
"<tr><td><code>{}extern crate {} as {};",
- myitem.visibility.print_with_space(),
+ myitem.visibility.print_with_space(cx.tcx()),
anchor(myitem.def_id, &*src.as_str()),
name
),
None => write!(
w,
"<tr><td><code>{}extern crate {};",
- myitem.visibility.print_with_space(),
+ myitem.visibility.print_with_space(cx.tcx()),
anchor(myitem.def_id, &*name.as_str())
),
}
write!(
w,
"<tr><td><code>{}{}</code></td></tr>",
- myitem.visibility.print_with_space(),
+ myitem.visibility.print_with_space(cx.tcx()),
import.print()
);
}
write!(
w,
"{vis}const {name}: {typ}",
- vis = it.visibility.print_with_space(),
+ vis = it.visibility.print_with_space(cx.tcx()),
name = it.name.as_ref().unwrap(),
typ = c.type_.print(),
);
write!(
w,
"{vis}static {mutability}{name}: {typ}</pre>",
- vis = it.visibility.print_with_space(),
+ vis = it.visibility.print_with_space(cx.tcx()),
mutability = s.mutability.print_with_space(),
name = it.name.as_ref().unwrap(),
typ = s.type_.print()
fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::Function) {
let header_len = format!(
"{}{}{}{}{:#}fn {}{:#}",
- it.visibility.print_with_space(),
+ it.visibility.print_with_space(cx.tcx()),
f.header.constness.print_with_space(),
f.header.asyncness.print_with_space(),
f.header.unsafety.print_with_space(),
w,
"{vis}{constness}{asyncness}{unsafety}{abi}fn \
{name}{generics}{decl}{spotlight}{where_clause}</pre>",
- vis = it.visibility.print_with_space(),
+ vis = it.visibility.print_with_space(cx.tcx()),
constness = f.header.constness.print_with_space(),
asyncness = f.header.asyncness.print_with_space(),
unsafety = f.header.unsafety.print_with_space(),
write!(
w,
"{}{}{}trait {}{}{}",
- it.visibility.print_with_space(),
+ it.visibility.print_with_space(cx.tcx()),
t.unsafety.print_with_space(),
if t.is_auto { "auto " } else { "" },
it.name.as_ref().unwrap(),
// FIXME: we should be using a derived_id for the Anchors here
write!(w, "{{\n");
for t in &types {
- render_assoc_item(w, t, AssocItemLink::Anchor(None), ItemType::Trait);
+ render_assoc_item(w, t, AssocItemLink::Anchor(None), ItemType::Trait, cx);
write!(w, ";\n");
}
if !types.is_empty() && !consts.is_empty() {
w.write_str("\n");
}
for t in &consts {
- render_assoc_item(w, t, AssocItemLink::Anchor(None), ItemType::Trait);
+ render_assoc_item(w, t, AssocItemLink::Anchor(None), ItemType::Trait, cx);
write!(w, ";\n");
}
if !consts.is_empty() && !required.is_empty() {
w.write_str("\n");
}
for (pos, m) in required.iter().enumerate() {
- render_assoc_item(w, m, AssocItemLink::Anchor(None), ItemType::Trait);
+ render_assoc_item(w, m, AssocItemLink::Anchor(None), ItemType::Trait, cx);
write!(w, ";\n");
if pos < required.len() - 1 {
w.write_str("\n");
}
for (pos, m) in provided.iter().enumerate() {
- render_assoc_item(w, m, AssocItemLink::Anchor(None), ItemType::Trait);
+ render_assoc_item(w, m, AssocItemLink::Anchor(None), ItemType::Trait, cx);
match m.kind {
clean::MethodItem(ref inner, _)
if !inner.generics.where_predicates.is_empty() =>
let item_type = m.type_();
let id = cx.derive_id(format!("{}.{}", item_type, name));
write!(w, "<h3 id=\"{id}\" class=\"method\"><code>", id = id,);
- render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl);
+ render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl, cx);
write!(w, "</code>");
render_stability_since(w, m, t);
write_srclink(cx, m, w, cache);
_default: Option<&String>,
link: AssocItemLink<'_>,
extra: &str,
+ cx: &Context<'_>,
) {
write!(
w,
"{}{}const <a href=\"{}\" class=\"constant\"><b>{}</b></a>: {}",
extra,
- it.visibility.print_with_space(),
+ it.visibility.print_with_space(cx.tcx()),
naive_assoc_href(it, link),
it.name.as_ref().unwrap(),
ty.print()
item: &clean::Item,
link: AssocItemLink<'_>,
parent: ItemType,
+ cx: &Context<'_>,
) {
fn method(
w: &mut Buffer,
d: &clean::FnDecl,
link: AssocItemLink<'_>,
parent: ItemType,
+ cx: &Context<'_>,
) {
let name = meth.name.as_ref().unwrap();
let anchor = format!("#{}.{}", meth.type_(), name);
};
let mut header_len = format!(
"{}{}{}{}{}{:#}fn {}{:#}",
- meth.visibility.print_with_space(),
+ meth.visibility.print_with_space(cx.tcx()),
header.constness.print_with_space(),
header.asyncness.print_with_space(),
header.unsafety.print_with_space(),
"{}{}{}{}{}{}{}fn <a href=\"{href}\" class=\"fnname\">{name}</a>\
{generics}{decl}{spotlight}{where_clause}",
if parent == ItemType::Trait { " " } else { "" },
- meth.visibility.print_with_space(),
+ meth.visibility.print_with_space(cx.tcx()),
header.constness.print_with_space(),
header.asyncness.print_with_space(),
header.unsafety.print_with_space(),
}
match item.kind {
clean::StrippedItem(..) => {}
- clean::TyMethodItem(ref m) => method(w, item, m.header, &m.generics, &m.decl, link, parent),
+ clean::TyMethodItem(ref m) => {
+ method(w, item, m.header, &m.generics, &m.decl, link, parent, cx)
+ }
clean::MethodItem(ref m, _) => {
- method(w, item, m.header, &m.generics, &m.decl, link, parent)
+ method(w, item, m.header, &m.generics, &m.decl, link, parent, cx)
}
clean::AssocConstItem(ref ty, ref default) => assoc_const(
w,
default.as_ref(),
link,
if parent == ItemType::Trait { " " } else { "" },
+ cx,
),
clean::AssocTypeItem(ref bounds, ref default) => assoc_type(
w,
wrap_into_docblock(w, |w| {
write!(w, "<pre class=\"rust struct\">");
render_attributes(w, it, true);
- render_struct(w, it, Some(&s.generics), s.struct_type, &s.fields, "", true);
+ render_struct(w, it, Some(&s.generics), s.struct_type, &s.fields, "", true, cx);
write!(w, "</pre>")
});
wrap_into_docblock(w, |w| {
write!(w, "<pre class=\"rust union\">");
render_attributes(w, it, true);
- render_union(w, it, Some(&s.generics), &s.fields, "", true);
+ render_union(w, it, Some(&s.generics), &s.fields, "", true, cx);
write!(w, "</pre>")
});
write!(
w,
"{}enum {}{}{}",
- it.visibility.print_with_space(),
+ it.visibility.print_with_space(cx.tcx()),
it.name.as_ref().unwrap(),
e.generics.print(),
WhereClause { gens: &e.generics, indent: 0, end_newline: true }
write!(w, ")");
}
clean::VariantKind::Struct(ref s) => {
- render_struct(w, v, None, s.struct_type, &s.fields, " ", false);
+ render_struct(w, v, None, s.struct_type, &s.fields, " ", false, cx);
}
},
_ => unreachable!(),
fields: &[clean::Item],
tab: &str,
structhead: bool,
+ cx: &Context<'_>,
) {
write!(
w,
"{}{}{}",
- it.visibility.print_with_space(),
+ it.visibility.print_with_space(cx.tcx()),
if structhead { "struct " } else { "" },
it.name.as_ref().unwrap()
);
w,
"\n{} {}{}: {},",
tab,
- field.visibility.print_with_space(),
+ field.visibility.print_with_space(cx.tcx()),
field.name.as_ref().unwrap(),
ty.print()
);
match field.kind {
clean::StrippedItem(box clean::StructFieldItem(..)) => write!(w, "_"),
clean::StructFieldItem(ref ty) => {
- write!(w, "{}{}", field.visibility.print_with_space(), ty.print())
+ write!(w, "{}{}", field.visibility.print_with_space(cx.tcx()), ty.print())
}
_ => unreachable!(),
}
fields: &[clean::Item],
tab: &str,
structhead: bool,
+ cx: &Context<'_>,
) {
write!(
w,
"{}{}{}",
- it.visibility.print_with_space(),
+ it.visibility.print_with_space(cx.tcx()),
if structhead { "union " } else { "" },
it.name.as_ref().unwrap()
);
write!(
w,
" {}{}: {},\n{}",
- field.visibility.print_with_space(),
+ field.visibility.print_with_space(cx.tcx()),
field.name.as_ref().unwrap(),
ty.print(),
tab
let id = cx.derive_id(format!("{}.{}", item_type, name));
write!(w, "<h4 id=\"{}\" class=\"{}{}\">", id, item_type, extra_class);
write!(w, "<code>");
- render_assoc_item(w, item, link.anchor(&id), ItemType::Impl);
+ render_assoc_item(w, item, link.anchor(&id), ItemType::Impl, cx);
write!(w, "</code>");
render_stability_since_raw(
w,
clean::AssocConstItem(ref ty, ref default) => {
let id = cx.derive_id(format!("{}.{}", item_type, name));
write!(w, "<h4 id=\"{}\" class=\"{}{}\"><code>", id, item_type, extra_class);
- assoc_const(w, item, ty, default.as_ref(), link.anchor(&id), "");
+ assoc_const(w, item, ty, default.as_ref(), link.anchor(&id), "", cx);
write!(w, "</code>");
render_stability_since_raw(
w,
write!(
w,
" {}type {};\n}}</pre>",
- it.visibility.print_with_space(),
+ it.visibility.print_with_space(cx.tcx()),
it.name.as_ref().unwrap(),
);