1
Fork 0

Move to print functions on types instead of impl fmt::Display

This will eventually allow us to easily pass in more parameters to the
functions without TLS or other such hacks
This commit is contained in:
Mark Rousskov 2019-09-12 19:59:14 -04:00
parent eb48d6bdee
commit 04b27efa00
8 changed files with 591 additions and 561 deletions

View file

@ -1849,7 +1849,7 @@ fn get_real_types(
cx: &DocContext<'_>, cx: &DocContext<'_>,
recurse: i32, recurse: i32,
) -> FxHashSet<Type> { ) -> FxHashSet<Type> {
let arg_s = arg.to_string(); let arg_s = arg.print().to_string();
let mut res = FxHashSet::default(); let mut res = FxHashSet::default();
if recurse >= 10 { // FIXME: remove this whole recurse thing when the recursion bug is fixed if recurse >= 10 { // FIXME: remove this whole recurse thing when the recursion bug is fixed
return res; return res;
@ -3573,16 +3573,6 @@ pub enum GenericArg {
Const(Constant), Const(Constant),
} }
impl fmt::Display for GenericArg {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
GenericArg::Lifetime(lt) => lt.fmt(f),
GenericArg::Type(ty) => ty.fmt(f),
GenericArg::Const(ct) => ct.fmt(f),
}
}
}
#[derive(Clone, PartialEq, Eq, Debug, Hash)] #[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub enum GenericArgs { pub enum GenericArgs {
AngleBracketed { AngleBracketed {
@ -4274,7 +4264,7 @@ fn resolve_type(cx: &DocContext<'_>,
return Generic(kw::SelfUpper.to_string()); return Generic(kw::SelfUpper.to_string());
} }
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => { Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => {
return Generic(format!("{:#}", path)); return Generic(format!("{:#}", path.print()));
} }
Res::SelfTy(..) Res::SelfTy(..)
| Res::Def(DefKind::TyParam, _) | Res::Def(DefKind::TyParam, _)

File diff suppressed because it is too large Load diff

View file

@ -46,14 +46,6 @@ pub enum ItemType {
} }
#[derive(Copy, Eq, PartialEq, Clone)]
pub enum NameSpace {
Type,
Value,
Macro,
Keyword,
}
impl<'a> From<&'a clean::Item> for ItemType { impl<'a> From<&'a clean::Item> for ItemType {
fn from(item: &'a clean::Item) -> ItemType { fn from(item: &'a clean::Item) -> ItemType {
let inner = match item.inner { let inner = match item.inner {
@ -120,7 +112,7 @@ impl From<clean::TypeKind> for ItemType {
} }
impl ItemType { impl ItemType {
pub fn css_class(&self) -> &'static str { pub fn as_str(&self) -> &'static str {
match *self { match *self {
ItemType::Module => "mod", ItemType::Module => "mod",
ItemType::ExternCrate => "externcrate", ItemType::ExternCrate => "externcrate",
@ -151,7 +143,7 @@ impl ItemType {
} }
} }
pub fn name_space(&self) -> NameSpace { pub fn name_space(&self) -> &'static str {
match *self { match *self {
ItemType::Struct | ItemType::Struct |
ItemType::Union | ItemType::Union |
@ -163,7 +155,7 @@ impl ItemType {
ItemType::AssocType | ItemType::AssocType |
ItemType::OpaqueTy | ItemType::OpaqueTy |
ItemType::TraitAlias | ItemType::TraitAlias |
ItemType::ForeignType => NameSpace::Type, ItemType::ForeignType => NAMESPACE_TYPE,
ItemType::ExternCrate | ItemType::ExternCrate |
ItemType::Import | ItemType::Import |
@ -175,20 +167,20 @@ impl ItemType {
ItemType::StructField | ItemType::StructField |
ItemType::Variant | ItemType::Variant |
ItemType::Constant | ItemType::Constant |
ItemType::AssocConst => NameSpace::Value, ItemType::AssocConst => NAMESPACE_VALUE,
ItemType::Macro | ItemType::Macro |
ItemType::ProcAttribute | ItemType::ProcAttribute |
ItemType::ProcDerive => NameSpace::Macro, ItemType::ProcDerive => NAMESPACE_MACRO,
ItemType::Keyword => NameSpace::Keyword, ItemType::Keyword => NAMESPACE_KEYWORD,
} }
} }
} }
impl fmt::Display for ItemType { impl fmt::Display for ItemType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.css_class().fmt(f) write!(f, "{}", self.as_str())
} }
} }
@ -196,20 +188,3 @@ pub const NAMESPACE_TYPE: &'static str = "t";
pub const NAMESPACE_VALUE: &'static str = "v"; pub const NAMESPACE_VALUE: &'static str = "v";
pub const NAMESPACE_MACRO: &'static str = "m"; pub const NAMESPACE_MACRO: &'static str = "m";
pub const NAMESPACE_KEYWORD: &'static str = "k"; pub const NAMESPACE_KEYWORD: &'static str = "k";
impl NameSpace {
pub fn to_static_str(&self) -> &'static str {
match *self {
NameSpace::Type => NAMESPACE_TYPE,
NameSpace::Value => NAMESPACE_VALUE,
NameSpace::Macro => NAMESPACE_MACRO,
NameSpace::Keyword => NAMESPACE_KEYWORD,
}
}
}
impl fmt::Display for NameSpace {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.to_static_str().fmt(f)
}
}

View file

@ -66,7 +66,7 @@ use crate::doctree;
use crate::fold::DocFolder; use crate::fold::DocFolder;
use crate::html::escape::Escape; use crate::html::escape::Escape;
use crate::html::format::{Buffer, AsyncSpace, ConstnessSpace}; use crate::html::format::{Buffer, AsyncSpace, ConstnessSpace};
use crate::html::format::{GenericBounds, WhereClause, href, AbiSpace, DefaultSpace}; use crate::html::format::{print_generic_bounds, WhereClause, href, AbiSpace, DefaultSpace};
use crate::html::format::{VisSpace, Function, UnsafetySpace, MutableSpace}; use crate::html::format::{VisSpace, Function, UnsafetySpace, MutableSpace};
use crate::html::format::fmt_impl_for_trait_page; use crate::html::format::fmt_impl_for_trait_page;
use crate::html::item_type::ItemType; use crate::html::item_type::ItemType;
@ -1203,7 +1203,7 @@ themePicker.onblur = handleThemeButtonsBlur;
if !imp.impl_item.def_id.is_local() { continue } if !imp.impl_item.def_id.is_local() { continue }
have_impls = true; have_impls = true;
write!(implementors, "{{text:{},synthetic:{},types:{}}},", write!(implementors, "{{text:{},synthetic:{},types:{}}},",
as_json(&imp.inner_impl().to_string()), as_json(&imp.inner_impl().print().to_string()),
imp.inner_impl().synthetic, imp.inner_impl().synthetic,
as_json(&collect_paths_for_type(imp.inner_impl().for_.clone()))).unwrap(); as_json(&collect_paths_for_type(imp.inner_impl().for_.clone()))).unwrap();
} }
@ -1222,7 +1222,7 @@ themePicker.onblur = handleThemeButtonsBlur;
} }
cx.shared.ensure_dir(&mydst)?; cx.shared.ensure_dir(&mydst)?;
mydst.push(&format!("{}.{}.js", mydst.push(&format!("{}.{}.js",
remote_item_type.css_class(), remote_item_type,
remote_path[remote_path.len() - 1])); remote_path[remote_path.len() - 1]));
let (mut all_implementors, _, _) = try_err!(collect(&mydst, &krate.name, "implementors", let (mut all_implementors, _, _) = try_err!(collect(&mydst, &krate.name, "implementors",
@ -1665,9 +1665,11 @@ impl ItemEntry {
} }
} }
impl fmt::Display for ItemEntry { impl ItemEntry {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { crate fn print(&self) -> impl fmt::Display + '_ {
write!(f, "<a href='{}'>{}</a>", self.url, Escape(&self.name)) crate::html::format::display_fn(move |f| {
write!(f, "<a href='{}'>{}</a>", self.url, Escape(&self.name))
})
} }
} }
@ -1759,7 +1761,7 @@ fn print_entries(f: &mut Buffer, e: &FxHashSet<ItemEntry>, title: &str, class: &
title, title,
Escape(title), Escape(title),
class, class,
e.iter().map(|s| format!("<li>{}</li>", s)).collect::<String>()); e.iter().map(|s| format!("<li>{}</li>", s.print())).collect::<String>());
} }
} }
@ -1939,7 +1941,7 @@ impl Context {
title.push_str(it.name.as_ref().unwrap()); title.push_str(it.name.as_ref().unwrap());
} }
title.push_str(" - Rust"); title.push_str(" - Rust");
let tyname = it.type_().css_class(); let tyname = it.type_();
let desc = if it.is_crate() { let desc = if it.is_crate() {
format!("API documentation for the Rust `{}` crate.", format!("API documentation for the Rust `{}` crate.",
self.shared.layout.krate) self.shared.layout.krate)
@ -1949,7 +1951,7 @@ impl Context {
}; };
let keywords = make_item_keywords(it); let keywords = make_item_keywords(it);
let page = layout::Page { let page = layout::Page {
css_class: tyname, css_class: tyname.as_str(),
root_path: &self.root_path(), root_path: &self.root_path(),
static_root_path: self.shared.static_root_path.as_deref(), static_root_path: self.shared.static_root_path.as_deref(),
title: &title, title: &title,
@ -2090,7 +2092,7 @@ impl Context {
for item in &m.items { for item in &m.items {
if item.is_stripped() { continue } if item.is_stripped() { continue }
let short = item.type_().css_class(); let short = item.type_();
let myname = match item.name { let myname = match item.name {
None => continue, None => continue,
Some(ref s) => s.to_string(), Some(ref s) => s.to_string(),
@ -2285,7 +2287,7 @@ fn print_item(cx: &Context, item: &clean::Item, buf: &mut Buffer) {
fn item_path(ty: ItemType, name: &str) -> String { fn item_path(ty: ItemType, name: &str) -> String {
match ty { match ty {
ItemType::Module => format!("{}index.html", SlashChecker(name)), ItemType::Module => format!("{}index.html", SlashChecker(name)),
_ => format!("{}.{}.html", ty.css_class(), name), _ => format!("{}.{}.html", ty, name),
} }
} }
@ -2586,7 +2588,7 @@ fn item_module(w: &mut Buffer, cx: &Context, item: &clean::Item, items: &[clean:
clean::ImportItem(ref import) => { clean::ImportItem(ref import) => {
write!(w, "<tr><td><code>{}{}</code></td></tr>", write!(w, "<tr><td><code>{}{}</code></td></tr>",
VisSpace(&myitem.visibility), *import); VisSpace(&myitem.visibility), import.print());
} }
_ => { _ => {
@ -2794,7 +2796,7 @@ fn item_constant(w: &mut Buffer, cx: &Context, it: &clean::Item, c: &clean::Cons
{name}: {typ}</pre>", {name}: {typ}</pre>",
vis = VisSpace(&it.visibility), vis = VisSpace(&it.visibility),
name = it.name.as_ref().unwrap(), name = it.name.as_ref().unwrap(),
typ = c.type_); typ = c.type_.print());
document(w, cx, it) document(w, cx, it)
} }
@ -2806,7 +2808,7 @@ fn item_static(w: &mut Buffer, cx: &Context, it: &clean::Item, s: &clean::Static
vis = VisSpace(&it.visibility), vis = VisSpace(&it.visibility),
mutability = MutableSpace(s.mutability), mutability = MutableSpace(s.mutability),
name = it.name.as_ref().unwrap(), name = it.name.as_ref().unwrap(),
typ = s.type_); typ = s.type_.print());
document(w, cx, it) document(w, cx, it)
} }
@ -2819,7 +2821,7 @@ fn item_function(w: &mut Buffer, cx: &Context, it: &clean::Item, f: &clean::Func
AsyncSpace(f.header.asyncness), AsyncSpace(f.header.asyncness),
AbiSpace(f.header.abi), AbiSpace(f.header.abi),
it.name.as_ref().unwrap(), it.name.as_ref().unwrap(),
f.generics f.generics.print()
).len(); ).len();
write!(w, "{}<pre class='rust fn'>", render_spotlight_traits(it)); write!(w, "{}<pre class='rust fn'>", render_spotlight_traits(it));
render_attributes(w, it, false); render_attributes(w, it, false);
@ -2832,14 +2834,14 @@ fn item_function(w: &mut Buffer, cx: &Context, it: &clean::Item, f: &clean::Func
asyncness = AsyncSpace(f.header.asyncness), asyncness = AsyncSpace(f.header.asyncness),
abi = AbiSpace(f.header.abi), abi = AbiSpace(f.header.abi),
name = it.name.as_ref().unwrap(), name = it.name.as_ref().unwrap(),
generics = f.generics, generics = f.generics.print(),
where_clause = WhereClause { gens: &f.generics, indent: 0, end_newline: true }, where_clause = WhereClause { gens: &f.generics, indent: 0, end_newline: true },
decl = Function { decl = Function {
decl: &f.decl, decl: &f.decl,
header_len, header_len,
indent: 0, indent: 0,
asyncness: f.header.asyncness, asyncness: f.header.asyncness,
}); }.print());
document(w, cx, it) document(w, cx, it)
} }
@ -2880,15 +2882,15 @@ fn bounds(t_bounds: &[clean::GenericBound], trait_alias: bool) -> String {
if i > 0 { if i > 0 {
bounds.push_str(" + "); bounds.push_str(" + ");
} }
bounds.push_str(&(*p).to_string()); bounds.push_str(&p.print().to_string());
} }
} }
bounds bounds
} }
fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl) -> Ordering { fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl) -> Ordering {
let lhs = format!("{}", lhs.inner_impl()); let lhs = format!("{}", lhs.inner_impl().print());
let rhs = format!("{}", rhs.inner_impl()); let rhs = format!("{}", rhs.inner_impl().print());
// lhs and rhs are formatted as HTML, which may be unnecessary // lhs and rhs are formatted as HTML, which may be unnecessary
name_key(&lhs).cmp(&name_key(&rhs)) name_key(&lhs).cmp(&name_key(&rhs))
@ -2915,7 +2917,7 @@ fn item_trait(
UnsafetySpace(t.unsafety), UnsafetySpace(t.unsafety),
if t.is_auto { "auto " } else { "" }, if t.is_auto { "auto " } else { "" },
it.name.as_ref().unwrap(), it.name.as_ref().unwrap(),
t.generics, t.generics.print(),
bounds); bounds);
if !t.generics.where_predicates.is_empty() { if !t.generics.where_predicates.is_empty() {
@ -3142,7 +3144,7 @@ fn item_trait(
let (ref path, _) = cache.external_paths[&it.def_id]; let (ref path, _) = cache.external_paths[&it.def_id];
path[..path.len() - 1].join("/") path[..path.len() - 1].join("/")
}, },
ty = it.type_().css_class(), ty = it.type_(),
name = *it.name.as_ref().unwrap()); name = *it.name.as_ref().unwrap());
} }
@ -3176,7 +3178,7 @@ fn assoc_const(w: &mut Buffer,
VisSpace(&it.visibility), VisSpace(&it.visibility),
naive_assoc_href(it, link), naive_assoc_href(it, link),
it.name.as_ref().unwrap(), it.name.as_ref().unwrap(),
ty); ty.print());
} }
fn assoc_type(w: &mut Buffer, it: &clean::Item, fn assoc_type(w: &mut Buffer, it: &clean::Item,
@ -3189,10 +3191,10 @@ fn assoc_type(w: &mut Buffer, it: &clean::Item,
naive_assoc_href(it, link), naive_assoc_href(it, link),
it.name.as_ref().unwrap()); it.name.as_ref().unwrap());
if !bounds.is_empty() { if !bounds.is_empty() {
write!(w, ": {}", GenericBounds(bounds)) write!(w, ": {}", print_generic_bounds(bounds))
} }
if let Some(default) = default { if let Some(default) = default {
write!(w, " = {}", default) write!(w, " = {}", default.print())
} }
} }
@ -3245,7 +3247,7 @@ fn render_assoc_item(w: &mut Buffer,
DefaultSpace(meth.is_default()), DefaultSpace(meth.is_default()),
AbiSpace(header.abi), AbiSpace(header.abi),
name, name,
*g g.print()
).len(); ).len();
let (indent, end_newline) = if parent == ItemType::Trait { let (indent, end_newline) = if parent == ItemType::Trait {
header_len += 4; header_len += 4;
@ -3265,13 +3267,13 @@ fn render_assoc_item(w: &mut Buffer,
AbiSpace(header.abi), AbiSpace(header.abi),
href = href, href = href,
name = name, name = name,
generics = *g, generics = g.print(),
decl = Function { decl = Function {
decl: d, decl: d,
header_len, header_len,
indent, indent,
asyncness: header.asyncness, asyncness: header.asyncness,
}, }.print(),
where_clause = WhereClause { where_clause = WhereClause {
gens: g, gens: g,
indent, indent,
@ -3340,7 +3342,7 @@ fn item_struct(w: &mut Buffer, cx: &Context, it: &clean::Item, s: &clean::Struct
id = id, id = id,
ns_id = ns_id, ns_id = ns_id,
name = field.name.as_ref().unwrap(), name = field.name.as_ref().unwrap(),
ty = ty); ty = ty.print());
document(w, cx, field); document(w, cx, field);
} }
} }
@ -3381,7 +3383,7 @@ fn item_union(w: &mut Buffer, cx: &Context, it: &clean::Item, s: &clean::Union)
id = id, id = id,
name = name, name = name,
shortty = ItemType::StructField, shortty = ItemType::StructField,
ty = ty); ty = ty.print());
if let Some(stability_class) = field.stability_class() { if let Some(stability_class) = field.stability_class() {
write!(w, "<span class='stab {stab}'></span>", write!(w, "<span class='stab {stab}'></span>",
stab = stability_class); stab = stability_class);
@ -3399,7 +3401,7 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum) {
write!(w, "{}enum {}{}{}", write!(w, "{}enum {}{}{}",
VisSpace(&it.visibility), VisSpace(&it.visibility),
it.name.as_ref().unwrap(), it.name.as_ref().unwrap(),
e.generics, e.generics.print(),
WhereClause { gens: &e.generics, indent: 0, end_newline: true }); WhereClause { gens: &e.generics, indent: 0, end_newline: true });
if e.variants.is_empty() && !e.variants_stripped { if e.variants.is_empty() && !e.variants_stripped {
write!(w, " {{}}"); write!(w, " {{}}");
@ -3418,7 +3420,7 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum) {
if i > 0 { if i > 0 {
write!(w, ",&nbsp;") write!(w, ",&nbsp;")
} }
write!(w, "{}", *ty); write!(w, "{}", ty.print());
} }
write!(w, ")"); write!(w, ")");
} }
@ -3472,7 +3474,7 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum) {
if i > 0 { if i > 0 {
write!(w, ",&nbsp;"); write!(w, ",&nbsp;");
} }
write!(w, "{}", *ty); write!(w, "{}", ty.print());
} }
write!(w, ")"); write!(w, ")");
} }
@ -3510,7 +3512,7 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum) {
id = id, id = id,
ns_id = ns_id, ns_id = ns_id,
f = field.name.as_ref().unwrap(), f = field.name.as_ref().unwrap(),
t = *ty); t = ty.print());
document(w, cx, field); document(w, cx, field);
} }
} }
@ -3590,7 +3592,7 @@ fn render_struct(w: &mut Buffer, it: &clean::Item,
if structhead {"struct "} else {""}, if structhead {"struct "} else {""},
it.name.as_ref().unwrap()); it.name.as_ref().unwrap());
if let Some(g) = g { if let Some(g) = g {
write!(w, "{}", g) write!(w, "{}", g.print())
} }
match ty { match ty {
doctree::Plain => { doctree::Plain => {
@ -3605,7 +3607,7 @@ fn render_struct(w: &mut Buffer, it: &clean::Item,
tab, tab,
VisSpace(&field.visibility), VisSpace(&field.visibility),
field.name.as_ref().unwrap(), field.name.as_ref().unwrap(),
*ty); ty.print());
has_visible_fields = true; has_visible_fields = true;
} }
} }
@ -3633,7 +3635,7 @@ fn render_struct(w: &mut Buffer, it: &clean::Item,
write!(w, "_") write!(w, "_")
} }
clean::StructFieldItem(ref ty) => { clean::StructFieldItem(ref ty) => {
write!(w, "{}{}", VisSpace(&field.visibility), *ty) write!(w, "{}{}", VisSpace(&field.visibility), ty.print())
} }
_ => unreachable!() _ => unreachable!()
} }
@ -3664,7 +3666,7 @@ fn render_union(w: &mut Buffer, it: &clean::Item,
if structhead {"union "} else {""}, if structhead {"union "} else {""},
it.name.as_ref().unwrap()); it.name.as_ref().unwrap());
if let Some(g) = g { if let Some(g) = g {
write!(w, "{}", g); write!(w, "{}", g.print());
write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: true }); write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: true });
} }
@ -3674,7 +3676,7 @@ fn render_union(w: &mut Buffer, it: &clean::Item,
write!(w, " {}{}: {},\n{}", write!(w, " {}{}: {},\n{}",
VisSpace(&field.visibility), VisSpace(&field.visibility),
field.name.as_ref().unwrap(), field.name.as_ref().unwrap(),
*ty, ty.print(),
tab); tab);
} }
} }
@ -3740,7 +3742,7 @@ fn render_assoc_items(w: &mut Buffer,
Methods from {}&lt;Target = {}&gt;\ Methods from {}&lt;Target = {}&gt;\
<a href='#deref-methods' class='anchor'></a>\ <a href='#deref-methods' class='anchor'></a>\
</h2>\ </h2>\
", trait_, type_); ", trait_.print(), type_.print());
RenderMode::ForDeref { mut_: deref_mut_ } RenderMode::ForDeref { mut_: deref_mut_ }
} }
}; };
@ -3885,12 +3887,13 @@ fn spotlight_decl(decl: &clean::FnDecl) -> String {
out.push_str( out.push_str(
&format!("<h3 class=\"important\">Important traits for {}</h3>\ &format!("<h3 class=\"important\">Important traits for {}</h3>\
<code class=\"content\">", <code class=\"content\">",
impl_.for_)); impl_.for_.print()));
trait_.push_str(&impl_.for_.to_string()); trait_.push_str(&impl_.for_.print().to_string());
} }
//use the "where" class here to make it small //use the "where" class here to make it small
out.push_str(&format!("<span class=\"where fmt-newline\">{}</span>", impl_)); out.push_str(
&format!("<span class=\"where fmt-newline\">{}</span>", impl_.print()));
let t_did = impl_.trait_.def_id().unwrap(); let t_did = impl_.trait_.def_id().unwrap();
for it in &impl_.items { for it in &impl_.items {
if let clean::TypedefItem(ref tydef, _) = it.inner { if let clean::TypedefItem(ref tydef, _) = it.inner {
@ -3927,7 +3930,7 @@ fn render_impl(w: &mut Buffer, cx: &Context, i: &Impl, link: AssocItemLink<'_>,
Some(ref t) => if is_on_foreign_type { 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)
} else { } else {
format!("impl-{}", small_url_encode(&format!("{:#}", t))) format!("impl-{}", small_url_encode(&format!("{:#}", t.print())))
}, },
None => "impl".to_string(), None => "impl".to_string(),
}); });
@ -3948,7 +3951,7 @@ fn render_impl(w: &mut Buffer, cx: &Context, i: &Impl, link: AssocItemLink<'_>,
write!(w, "</code>"); write!(w, "</code>");
} else { } else {
write!(w, "<h3 id='{}' class='impl'><code class='in-band'>{}</code>", write!(w, "<h3 id='{}' class='impl'><code class='in-band'>{}</code>",
id, i.inner_impl() id, i.inner_impl().print()
); );
} }
write!(w, "<a href='#{}' class='anchor'></a>", id); write!(w, "<a href='#{}' class='anchor'></a>", id);
@ -3993,8 +3996,10 @@ fn render_impl(w: &mut Buffer, cx: &Context, i: &Impl, link: AssocItemLink<'_>,
// Only render when the method is not static or we allow static methods // Only render when the method is not static or we allow static methods
if render_method_item { if render_method_item {
let id = cx.derive_id(format!("{}.{}", item_type, name)); let id = cx.derive_id(format!("{}.{}", item_type, name));
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space())); let ns_id = cx.derive_id(format!("{}.{}",
write!(w, "<h4 id='{}' class=\"{}{}\">", id, item_type, extra_class); name, item_type.name_space()));
write!(w, "<h4 id='{}' class=\"{}{}\">",
id, item_type, extra_class);
write!(w, "{}", spotlight_decl(decl)); write!(w, "{}", spotlight_decl(decl));
write!(w, "<code id='{}'>", ns_id); write!(w, "<code id='{}'>", ns_id);
render_assoc_item(w, item, link.anchor(&id), ItemType::Impl); render_assoc_item(w, item, link.anchor(&id), ItemType::Impl);
@ -4125,7 +4130,7 @@ fn item_opaque_ty(
render_attributes(w, it, false); render_attributes(w, it, false);
write!(w, "type {}{}{where_clause} = impl {bounds};</pre>", write!(w, "type {}{}{where_clause} = impl {bounds};</pre>",
it.name.as_ref().unwrap(), it.name.as_ref().unwrap(),
t.generics, t.generics.print(),
where_clause = WhereClause { gens: &t.generics, indent: 0, end_newline: true }, where_clause = WhereClause { gens: &t.generics, indent: 0, end_newline: true },
bounds = bounds(&t.bounds, false)); bounds = bounds(&t.bounds, false));
@ -4144,7 +4149,7 @@ fn item_trait_alias(w: &mut Buffer, cx: &Context, it: &clean::Item,
render_attributes(w, it, false); render_attributes(w, it, false);
write!(w, "trait {}{}{} = {};</pre>", write!(w, "trait {}{}{} = {};</pre>",
it.name.as_ref().unwrap(), it.name.as_ref().unwrap(),
t.generics, t.generics.print(),
WhereClause { gens: &t.generics, indent: 0, end_newline: true }, WhereClause { gens: &t.generics, indent: 0, end_newline: true },
bounds(&t.bounds, true)); bounds(&t.bounds, true));
@ -4162,9 +4167,9 @@ fn item_typedef(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Typed
render_attributes(w, it, false); render_attributes(w, it, false);
write!(w, "type {}{}{where_clause} = {type_};</pre>", write!(w, "type {}{}{where_clause} = {type_};</pre>",
it.name.as_ref().unwrap(), it.name.as_ref().unwrap(),
t.generics, t.generics.print(),
where_clause = WhereClause { gens: &t.generics, indent: 0, end_newline: true }, where_clause = WhereClause { gens: &t.generics, indent: 0, end_newline: true },
type_ = t.type_); type_ = t.type_.print());
document(w, cx, it); document(w, cx, it);
@ -4269,7 +4274,7 @@ fn print_sidebar(cx: &Context, it: &clean::Item, buffer: &mut Buffer) {
relpath: '{path}'\ relpath: '{path}'\
}};</script>", }};</script>",
name = it.name.as_ref().map(|x| &x[..]).unwrap_or(""), name = it.name.as_ref().map(|x| &x[..]).unwrap_or(""),
ty = it.type_().css_class(), ty = it.type_(),
path = relpath); path = relpath);
if parentlen == 0 { if parentlen == 0 {
// There is no sidebar-items.js beyond the crate root path // There is no sidebar-items.js beyond the crate root path
@ -4370,9 +4375,10 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
if let Some(impls) = inner_impl { if let Some(impls) = inner_impl {
out.push_str("<a class=\"sidebar-title\" href=\"#deref-methods\">"); out.push_str("<a class=\"sidebar-title\" href=\"#deref-methods\">");
out.push_str(&format!("Methods from {}&lt;Target={}&gt;", out.push_str(&format!("Methods from {}&lt;Target={}&gt;",
Escape(&format!("{:#}", Escape(&format!(
impl_.inner_impl().trait_.as_ref().unwrap())), "{:#}", impl_.inner_impl().trait_.as_ref().unwrap().print()
Escape(&format!("{:#}", target)))); )),
Escape(&format!("{:#}", target.print()))));
out.push_str("</a>"); out.push_str("</a>");
let mut ret = impls.iter() let mut ret = impls.iter()
.filter(|i| i.inner_impl().trait_.is_none()) .filter(|i| i.inner_impl().trait_.is_none())
@ -4397,9 +4403,9 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
.filter_map(|i| { .filter_map(|i| {
let is_negative_impl = is_negative_impl(i.inner_impl()); let is_negative_impl = is_negative_impl(i.inner_impl());
if let Some(ref i) = i.inner_impl().trait_ { if let Some(ref i) = i.inner_impl().trait_ {
let i_display = format!("{:#}", i); let i_display = format!("{:#}", i.print());
let out = Escape(&i_display); let out = Escape(&i_display);
let encoded = small_url_encode(&format!("{:#}", i)); let encoded = small_url_encode(&format!("{:#}", i.print()));
let generated = format!("<a href=\"#impl-{}\">{}{}</a>", let generated = format!("<a href=\"#impl-{}\">{}{}</a>",
encoded, encoded,
if is_negative_impl { "!" } else { "" }, if is_negative_impl { "!" } else { "" },
@ -4471,14 +4477,17 @@ fn sidebar_struct(buf: &mut Buffer, it: &clean::Item, s: &clean::Struct) {
} }
fn get_id_for_impl_on_foreign_type(for_: &clean::Type, trait_: &clean::Type) -> String { fn get_id_for_impl_on_foreign_type(for_: &clean::Type, trait_: &clean::Type) -> String {
small_url_encode(&format!("impl-{:#}-for-{:#}", trait_, for_)) small_url_encode(&format!("impl-{:#}-for-{:#}", trait_.print(), for_.print()))
} }
fn extract_for_impl_name(item: &clean::Item) -> Option<(String, String)> { fn extract_for_impl_name(item: &clean::Item) -> Option<(String, String)> {
match item.inner { match item.inner {
clean::ItemEnum::ImplItem(ref i) => { clean::ItemEnum::ImplItem(ref i) => {
if let Some(ref trait_) = i.trait_ { if let Some(ref trait_) = i.trait_ {
Some((format!("{:#}", i.for_), get_id_for_impl_on_foreign_type(&i.for_, trait_))) Some((
format!("{:#}", i.for_.print()),
get_id_for_impl_on_foreign_type(&i.for_, trait_),
))
} else { } else {
None None
} }

View file

@ -142,7 +142,8 @@ impl fold::DocFolder for CoverageCalculator {
} }
clean::ImplItem(ref impl_) => { clean::ImplItem(ref impl_) => {
if let Some(ref tr) = impl_.trait_ { if let Some(ref tr) = impl_.trait_ {
debug!("impl {:#} for {:#} in {}", tr, impl_.for_, i.source.filename); debug!("impl {:#} for {:#} in {}",
tr.print(), impl_.for_.print(), i.source.filename);
// don't count trait impls, the missing-docs lint doesn't so we shouldn't // don't count trait impls, the missing-docs lint doesn't so we shouldn't
// either // either
@ -151,11 +152,11 @@ impl fold::DocFolder for CoverageCalculator {
// inherent impls *can* be documented, and those docs show up, but in most // 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 // cases it doesn't make sense, as all methods on a type are in one single
// impl block // impl block
debug!("impl {:#} in {}", impl_.for_, i.source.filename); debug!("impl {:#} in {}", impl_.for_.print(), i.source.filename);
} }
} }
_ => { _ => {
debug!("counting {} {:?} in {}", i.type_(), i.name, i.source.filename); debug!("counting {:?} {:?} in {}", i.type_(), i.name, i.source.filename);
self.items.entry(i.source.filename.clone()) self.items.entry(i.source.filename.clone())
.or_default() .or_default()
.count_item(has_docs); .count_item(has_docs);

View file

@ -237,7 +237,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
}); });
if parent_node.is_some() { if parent_node.is_some() {
debug!("got parent node for {} {:?}, id {:?}", item.type_(), item.name, item.def_id); debug!("got parent node for {:?} {:?}, id {:?}", item.type_(), item.name, item.def_id);
} }
let current_item = match item.inner { let current_item = match item.inner {

View file

@ -153,7 +153,7 @@ impl<'a> DocFolder for Stripper<'a> {
// We need to recurse into stripped modules to strip things // We need to recurse into stripped modules to strip things
// like impl methods but when doing so we must not add any // like impl methods but when doing so we must not add any
// items to the `retained` set. // items to the `retained` set.
debug!("Stripper: recursing into stripped {} {:?}", i.type_(), i.name); debug!("Stripper: recursing into stripped {:?} {:?}", i.type_(), i.name);
let old = mem::replace(&mut self.update_retained, false); let old = mem::replace(&mut self.update_retained, false);
let ret = self.fold_item_recur(i); let ret = self.fold_item_recur(i);
self.update_retained = old; self.update_retained = old;
@ -178,7 +178,7 @@ impl<'a> DocFolder for Stripper<'a> {
| clean::ForeignTypeItem => { | clean::ForeignTypeItem => {
if i.def_id.is_local() { if i.def_id.is_local() {
if !self.access_levels.is_exported(i.def_id) { if !self.access_levels.is_exported(i.def_id) {
debug!("Stripper: stripping {} {:?}", i.type_(), i.name); debug!("Stripper: stripping {:?} {:?}", i.type_(), i.name);
return None; return None;
} }
} }

View file

@ -39,7 +39,7 @@ struct Stripper<'a> {
impl<'a> DocFolder for Stripper<'a> { impl<'a> DocFolder for Stripper<'a> {
fn fold_item(&mut self, i: Item) -> Option<Item> { fn fold_item(&mut self, i: Item) -> Option<Item> {
if i.attrs.lists(sym::doc).has_word(sym::hidden) { if i.attrs.lists(sym::doc).has_word(sym::hidden) {
debug!("strip_hidden: stripping {} {:?}", i.type_(), i.name); debug!("strip_hidden: stripping {:?} {:?}", i.type_(), i.name);
// use a dedicated hidden item for given item type if any // use a dedicated hidden item for given item type if any
match i.inner { match i.inner {
clean::StructFieldItem(..) | clean::ModuleItem(..) => { clean::StructFieldItem(..) | clean::ModuleItem(..) => {