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<'_>,
recurse: i32,
) -> FxHashSet<Type> {
let arg_s = arg.to_string();
let arg_s = arg.print().to_string();
let mut res = FxHashSet::default();
if recurse >= 10 { // FIXME: remove this whole recurse thing when the recursion bug is fixed
return res;
@ -3573,16 +3573,6 @@ pub enum GenericArg {
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)]
pub enum GenericArgs {
AngleBracketed {
@ -4274,7 +4264,7 @@ fn resolve_type(cx: &DocContext<'_>,
return Generic(kw::SelfUpper.to_string());
}
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => {
return Generic(format!("{:#}", path));
return Generic(format!("{:#}", path.print()));
}
Res::SelfTy(..)
| 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 {
fn from(item: &'a clean::Item) -> ItemType {
let inner = match item.inner {
@ -120,7 +112,7 @@ fn from(kind: clean::TypeKind) -> ItemType {
}
impl ItemType {
pub fn css_class(&self) -> &'static str {
pub fn as_str(&self) -> &'static str {
match *self {
ItemType::Module => "mod",
ItemType::ExternCrate => "externcrate",
@ -151,7 +143,7 @@ pub fn css_class(&self) -> &'static str {
}
}
pub fn name_space(&self) -> NameSpace {
pub fn name_space(&self) -> &'static str {
match *self {
ItemType::Struct |
ItemType::Union |
@ -163,7 +155,7 @@ pub fn name_space(&self) -> NameSpace {
ItemType::AssocType |
ItemType::OpaqueTy |
ItemType::TraitAlias |
ItemType::ForeignType => NameSpace::Type,
ItemType::ForeignType => NAMESPACE_TYPE,
ItemType::ExternCrate |
ItemType::Import |
@ -175,20 +167,20 @@ pub fn name_space(&self) -> NameSpace {
ItemType::StructField |
ItemType::Variant |
ItemType::Constant |
ItemType::AssocConst => NameSpace::Value,
ItemType::AssocConst => NAMESPACE_VALUE,
ItemType::Macro |
ItemType::ProcAttribute |
ItemType::ProcDerive => NameSpace::Macro,
ItemType::ProcDerive => NAMESPACE_MACRO,
ItemType::Keyword => NameSpace::Keyword,
ItemType::Keyword => NAMESPACE_KEYWORD,
}
}
}
impl fmt::Display for ItemType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.css_class().fmt(f)
write!(f, "{}", self.as_str())
}
}
@ -196,20 +188,3 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
pub const NAMESPACE_VALUE: &'static str = "v";
pub const NAMESPACE_MACRO: &'static str = "m";
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::fold::DocFolder;
use crate::html::escape::Escape;
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::fmt_impl_for_trait_page;
use crate::html::item_type::ItemType;
@ -1203,7 +1203,7 @@ fn to_json_string(&self) -> String {
if !imp.impl_item.def_id.is_local() { continue }
have_impls = true;
write!(implementors, "{{text:{},synthetic:{},types:{}}},",
as_json(&imp.inner_impl().to_string()),
as_json(&imp.inner_impl().print().to_string()),
imp.inner_impl().synthetic,
as_json(&collect_paths_for_type(imp.inner_impl().for_.clone()))).unwrap();
}
@ -1222,7 +1222,7 @@ fn to_json_string(&self) -> String {
}
cx.shared.ensure_dir(&mydst)?;
mydst.push(&format!("{}.{}.js",
remote_item_type.css_class(),
remote_item_type,
remote_path[remote_path.len() - 1]));
let (mut all_implementors, _, _) = try_err!(collect(&mydst, &krate.name, "implementors",
@ -1665,9 +1665,11 @@ fn new(mut url: String, name: String) -> ItemEntry {
}
}
impl fmt::Display for ItemEntry {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "<a href='{}'>{}</a>", self.url, Escape(&self.name))
impl ItemEntry {
crate fn print(&self) -> impl fmt::Display + '_ {
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,
Escape(title),
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 @@ fn render_item(&self,
title.push_str(it.name.as_ref().unwrap());
}
title.push_str(" - Rust");
let tyname = it.type_().css_class();
let tyname = it.type_();
let desc = if it.is_crate() {
format!("API documentation for the Rust `{}` crate.",
self.shared.layout.krate)
@ -1949,7 +1951,7 @@ fn render_item(&self,
};
let keywords = make_item_keywords(it);
let page = layout::Page {
css_class: tyname,
css_class: tyname.as_str(),
root_path: &self.root_path(),
static_root_path: self.shared.static_root_path.as_deref(),
title: &title,
@ -2090,7 +2092,7 @@ fn build_sidebar_items(&self, m: &clean::Module) -> BTreeMap<String, Vec<NameDoc
for item in &m.items {
if item.is_stripped() { continue }
let short = item.type_().css_class();
let short = item.type_();
let myname = match item.name {
None => continue,
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 {
match ty {
ItemType::Module => format!("{}index.html", SlashChecker(name)),
_ => format!("{}.{}.html", ty.css_class(), name),
_ => format!("{}.{}.html", ty, name),
}
}
@ -2586,7 +2588,7 @@ fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: usize, idx2: usize) -> Ordering
clean::ImportItem(ref import) => {
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>",
vis = VisSpace(&it.visibility),
name = it.name.as_ref().unwrap(),
typ = c.type_);
typ = c.type_.print());
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),
mutability = MutableSpace(s.mutability),
name = it.name.as_ref().unwrap(),
typ = s.type_);
typ = s.type_.print());
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),
AbiSpace(f.header.abi),
it.name.as_ref().unwrap(),
f.generics
f.generics.print()
).len();
write!(w, "{}<pre class='rust fn'>", render_spotlight_traits(it));
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),
abi = AbiSpace(f.header.abi),
name = it.name.as_ref().unwrap(),
generics = f.generics,
generics = f.generics.print(),
where_clause = WhereClause { gens: &f.generics, indent: 0, end_newline: true },
decl = Function {
decl: &f.decl,
header_len,
indent: 0,
asyncness: f.header.asyncness,
});
}.print());
document(w, cx, it)
}
@ -2880,15 +2882,15 @@ fn bounds(t_bounds: &[clean::GenericBound], trait_alias: bool) -> String {
if i > 0 {
bounds.push_str(" + ");
}
bounds.push_str(&(*p).to_string());
bounds.push_str(&p.print().to_string());
}
}
bounds
}
fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl) -> Ordering {
let lhs = format!("{}", lhs.inner_impl());
let rhs = format!("{}", rhs.inner_impl());
let lhs = format!("{}", lhs.inner_impl().print());
let rhs = format!("{}", rhs.inner_impl().print());
// lhs and rhs are formatted as HTML, which may be unnecessary
name_key(&lhs).cmp(&name_key(&rhs))
@ -2915,7 +2917,7 @@ fn item_trait(
UnsafetySpace(t.unsafety),
if t.is_auto { "auto " } else { "" },
it.name.as_ref().unwrap(),
t.generics,
t.generics.print(),
bounds);
if !t.generics.where_predicates.is_empty() {
@ -3142,7 +3144,7 @@ fn trait_item(w: &mut Buffer, cx: &Context, m: &clean::Item, t: &clean::Item) {
let (ref path, _) = cache.external_paths[&it.def_id];
path[..path.len() - 1].join("/")
},
ty = it.type_().css_class(),
ty = it.type_(),
name = *it.name.as_ref().unwrap());
}
@ -3176,7 +3178,7 @@ fn assoc_const(w: &mut Buffer,
VisSpace(&it.visibility),
naive_assoc_href(it, link),
it.name.as_ref().unwrap(),
ty);
ty.print());
}
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),
it.name.as_ref().unwrap());
if !bounds.is_empty() {
write!(w, ": {}", GenericBounds(bounds))
write!(w, ": {}", print_generic_bounds(bounds))
}
if let Some(default) = default {
write!(w, " = {}", default)
write!(w, " = {}", default.print())
}
}
@ -3245,7 +3247,7 @@ fn method(w: &mut Buffer,
DefaultSpace(meth.is_default()),
AbiSpace(header.abi),
name,
*g
g.print()
).len();
let (indent, end_newline) = if parent == ItemType::Trait {
header_len += 4;
@ -3265,13 +3267,13 @@ fn method(w: &mut Buffer,
AbiSpace(header.abi),
href = href,
name = name,
generics = *g,
generics = g.print(),
decl = Function {
decl: d,
header_len,
indent,
asyncness: header.asyncness,
},
}.print(),
where_clause = WhereClause {
gens: g,
indent,
@ -3340,7 +3342,7 @@ fn item_struct(w: &mut Buffer, cx: &Context, it: &clean::Item, s: &clean::Struct
id = id,
ns_id = ns_id,
name = field.name.as_ref().unwrap(),
ty = ty);
ty = ty.print());
document(w, cx, field);
}
}
@ -3381,7 +3383,7 @@ fn item_union(w: &mut Buffer, cx: &Context, it: &clean::Item, s: &clean::Union)
id = id,
name = name,
shortty = ItemType::StructField,
ty = ty);
ty = ty.print());
if let Some(stability_class) = field.stability_class() {
write!(w, "<span class='stab {stab}'></span>",
stab = stability_class);
@ -3399,7 +3401,7 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum) {
write!(w, "{}enum {}{}{}",
VisSpace(&it.visibility),
it.name.as_ref().unwrap(),
e.generics,
e.generics.print(),
WhereClause { gens: &e.generics, indent: 0, end_newline: true });
if e.variants.is_empty() && !e.variants_stripped {
write!(w, " {{}}");
@ -3418,7 +3420,7 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum) {
if i > 0 {
write!(w, ",&nbsp;")
}
write!(w, "{}", *ty);
write!(w, "{}", ty.print());
}
write!(w, ")");
}
@ -3472,7 +3474,7 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum) {
if i > 0 {
write!(w, ",&nbsp;");
}
write!(w, "{}", *ty);
write!(w, "{}", ty.print());
}
write!(w, ")");
}
@ -3510,7 +3512,7 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum) {
id = id,
ns_id = ns_id,
f = field.name.as_ref().unwrap(),
t = *ty);
t = ty.print());
document(w, cx, field);
}
}
@ -3590,7 +3592,7 @@ fn render_struct(w: &mut Buffer, it: &clean::Item,
if structhead {"struct "} else {""},
it.name.as_ref().unwrap());
if let Some(g) = g {
write!(w, "{}", g)
write!(w, "{}", g.print())
}
match ty {
doctree::Plain => {
@ -3605,7 +3607,7 @@ fn render_struct(w: &mut Buffer, it: &clean::Item,
tab,
VisSpace(&field.visibility),
field.name.as_ref().unwrap(),
*ty);
ty.print());
has_visible_fields = true;
}
}
@ -3633,7 +3635,7 @@ fn render_struct(w: &mut Buffer, it: &clean::Item,
write!(w, "_")
}
clean::StructFieldItem(ref ty) => {
write!(w, "{}{}", VisSpace(&field.visibility), *ty)
write!(w, "{}{}", VisSpace(&field.visibility), ty.print())
}
_ => unreachable!()
}
@ -3664,7 +3666,7 @@ fn render_union(w: &mut Buffer, it: &clean::Item,
if structhead {"union "} else {""},
it.name.as_ref().unwrap());
if let Some(g) = g {
write!(w, "{}", g);
write!(w, "{}", g.print());
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{}",
VisSpace(&field.visibility),
field.name.as_ref().unwrap(),
*ty,
ty.print(),
tab);
}
}
@ -3740,7 +3742,7 @@ fn render_assoc_items(w: &mut Buffer,
Methods from {}&lt;Target = {}&gt;\
<a href='#deref-methods' class='anchor'></a>\
</h2>\
", trait_, type_);
", trait_.print(), type_.print());
RenderMode::ForDeref { mut_: deref_mut_ }
}
};
@ -3885,12 +3887,13 @@ fn spotlight_decl(decl: &clean::FnDecl) -> String {
out.push_str(
&format!("<h3 class=\"important\">Important traits for {}</h3>\
<code class=\"content\">",
impl_.for_));
trait_.push_str(&impl_.for_.to_string());
impl_.for_.print()));
trait_.push_str(&impl_.for_.print().to_string());
}
//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();
for it in &impl_.items {
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 {
get_id_for_impl_on_foreign_type(&i.inner_impl().for_, t)
} else {
format!("impl-{}", small_url_encode(&format!("{:#}", t)))
format!("impl-{}", small_url_encode(&format!("{:#}", t.print())))
},
None => "impl".to_string(),
});
@ -3948,7 +3951,7 @@ fn render_impl(w: &mut Buffer, cx: &Context, i: &Impl, link: AssocItemLink<'_>,
write!(w, "</code>");
} else {
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);
@ -3993,8 +3996,10 @@ fn doc_impl_item(w: &mut Buffer, cx: &Context, item: &clean::Item,
// Only render when the method is not static or we allow static methods
if render_method_item {
let id = cx.derive_id(format!("{}.{}", item_type, name));
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
write!(w, "<h4 id='{}' class=\"{}{}\">", id, item_type, extra_class);
let ns_id = cx.derive_id(format!("{}.{}",
name, item_type.name_space()));
write!(w, "<h4 id='{}' class=\"{}{}\">",
id, item_type, extra_class);
write!(w, "{}", spotlight_decl(decl));
write!(w, "<code id='{}'>", ns_id);
render_assoc_item(w, item, link.anchor(&id), ItemType::Impl);
@ -4125,7 +4130,7 @@ fn item_opaque_ty(
render_attributes(w, it, false);
write!(w, "type {}{}{where_clause} = impl {bounds};</pre>",
it.name.as_ref().unwrap(),
t.generics,
t.generics.print(),
where_clause = WhereClause { gens: &t.generics, indent: 0, end_newline: true },
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);
write!(w, "trait {}{}{} = {};</pre>",
it.name.as_ref().unwrap(),
t.generics,
t.generics.print(),
WhereClause { gens: &t.generics, indent: 0, end_newline: 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);
write!(w, "type {}{}{where_clause} = {type_};</pre>",
it.name.as_ref().unwrap(),
t.generics,
t.generics.print(),
where_clause = WhereClause { gens: &t.generics, indent: 0, end_newline: true },
type_ = t.type_);
type_ = t.type_.print());
document(w, cx, it);
@ -4269,7 +4274,7 @@ fn print_sidebar(cx: &Context, it: &clean::Item, buffer: &mut Buffer) {
relpath: '{path}'\
}};</script>",
name = it.name.as_ref().map(|x| &x[..]).unwrap_or(""),
ty = it.type_().css_class(),
ty = it.type_(),
path = relpath);
if parentlen == 0 {
// 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 {
out.push_str("<a class=\"sidebar-title\" href=\"#deref-methods\">");
out.push_str(&format!("Methods from {}&lt;Target={}&gt;",
Escape(&format!("{:#}",
impl_.inner_impl().trait_.as_ref().unwrap())),
Escape(&format!("{:#}", target))));
Escape(&format!(
"{:#}", impl_.inner_impl().trait_.as_ref().unwrap().print()
)),
Escape(&format!("{:#}", target.print()))));
out.push_str("</a>");
let mut ret = impls.iter()
.filter(|i| i.inner_impl().trait_.is_none())
@ -4397,9 +4403,9 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
.filter_map(|i| {
let is_negative_impl = is_negative_impl(i.inner_impl());
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 encoded = small_url_encode(&format!("{:#}", i));
let encoded = small_url_encode(&format!("{:#}", i.print()));
let generated = format!("<a href=\"#impl-{}\">{}{}</a>",
encoded,
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 {
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)> {
match item.inner {
clean::ItemEnum::ImplItem(ref i) => {
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 {
None
}

View File

@ -142,7 +142,8 @@ fn fold_item(&mut self, i: clean::Item) -> Option<clean::Item> {
}
clean::ImplItem(ref impl_) => {
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
// either
@ -151,11 +152,11 @@ fn fold_item(&mut self, i: clean::Item) -> Option<clean::Item> {
// 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_, 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())
.or_default()
.count_item(has_docs);

View File

@ -237,7 +237,7 @@ fn fold_item(&mut self, mut item: Item) -> Option<Item> {
});
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 {

View File

@ -153,7 +153,7 @@ fn fold_item(&mut self, i: Item) -> Option<Item> {
// We need to recurse into stripped modules to strip things
// like impl methods but when doing so we must not add any
// 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 ret = self.fold_item_recur(i);
self.update_retained = old;
@ -178,7 +178,7 @@ fn fold_item(&mut self, i: Item) -> Option<Item> {
| clean::ForeignTypeItem => {
if i.def_id.is_local() {
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;
}
}

View File

@ -39,7 +39,7 @@ struct Stripper<'a> {
impl<'a> DocFolder for Stripper<'a> {
fn fold_item(&mut self, i: Item) -> Option<Item> {
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
match i.inner {
clean::StructFieldItem(..) | clean::ModuleItem(..) => {