Skip to content

Commit

Permalink
rustdoc: Skip types in impls in search index
Browse files Browse the repository at this point in the history
For a trait *implementation* there are typedefs which are the types for
that particular trait and implementor. Skip these in the search index.

There were lots of dud items in the search index due to this (search for
Item, Iterator's associated type).

Add a boolean to clean::TypedefItem so that it tracks whether the it is
a type alias on its own, or if it's a `type` item in a trait impl.

Fixes #22442
  • Loading branch information
Ulrik Sverdrup committed May 21, 2015
1 parent d7185dc commit 093e18d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/librustdoc/clean/inline.rs
Expand Up @@ -216,7 +216,7 @@ fn build_type(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> clean::ItemEn
clean::TypedefItem(clean::Typedef {
type_: t.ty.clean(cx),
generics: (&t.generics, &predicates, subst::TypeSpace).clean(cx),
})
}, false)
}

pub fn build_impls(cx: &DocContext, tcx: &ty::ctxt,
Expand Down Expand Up @@ -368,7 +368,7 @@ pub fn build_impl(cx: &DocContext,
subst::ParamSpace::TypeSpace).clean(cx);
Some(clean::Item {
name: Some(assoc_ty.name.clean(cx)),
inner: clean::TypedefItem(typedef),
inner: clean::TypedefItem(typedef, true),
source: clean::Span::empty(),
attrs: vec![],
visibility: None,
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -343,7 +343,7 @@ pub enum ItemEnum {
EnumItem(Enum),
FunctionItem(Function),
ModuleItem(Module),
TypedefItem(Typedef),
TypedefItem(Typedef, bool /* is associated type */),
StaticItem(Static),
ConstantItem(Constant),
TraitItem(Trait),
Expand Down Expand Up @@ -1282,7 +1282,7 @@ impl Clean<Item> for ast::ImplItem {
type_params: Vec::new(),
where_predicates: Vec::new()
},
}),
}, true),
ast::MacImplItem(_) => {
MacroItem(Macro {
source: self.span.to_src(cx),
Expand Down Expand Up @@ -2078,7 +2078,7 @@ impl Clean<Item> for doctree::Typedef {
inner: TypedefItem(Typedef {
type_: self.ty.clean(cx),
generics: self.gen.clean(cx),
}),
}, false),
}
}
}
Expand Down Expand Up @@ -2248,7 +2248,7 @@ fn build_deref_target_impls(cx: &DocContext,

for item in items {
let target = match item.inner {
TypedefItem(ref t) => &t.type_,
TypedefItem(ref t, true) => &t.type_,
_ => continue,
};
let primitive = match *target {
Expand Down
14 changes: 9 additions & 5 deletions src/librustdoc/html/render.rs
Expand Up @@ -870,7 +870,7 @@ impl DocFolder for Cache {
clean::StructItem(ref s) => self.generics(&s.generics),
clean::EnumItem(ref e) => self.generics(&e.generics),
clean::FunctionItem(ref f) => self.generics(&f.generics),
clean::TypedefItem(ref t) => self.generics(&t.generics),
clean::TypedefItem(ref t, _) => self.generics(&t.generics),
clean::TraitItem(ref t) => self.generics(&t.generics),
clean::ImplItem(ref i) => self.generics(&i.generics),
clean::TyMethodItem(ref i) => self.generics(&i.generics),
Expand Down Expand Up @@ -936,6 +936,10 @@ impl DocFolder for Cache {
((Some(*last), path), true)
}
}
clean::TypedefItem(_, true) => {
// skip associated types in impls
((None, None), false)
}
_ => ((None, Some(&*self.stack)), false)
};
let hidden_field = match item.inner {
Expand Down Expand Up @@ -1497,7 +1501,7 @@ impl<'a> fmt::Display for Item<'a> {
clean::TraitItem(ref t) => item_trait(fmt, self.cx, self.item, t),
clean::StructItem(ref s) => item_struct(fmt, self.item, s),
clean::EnumItem(ref e) => item_enum(fmt, self.item, e),
clean::TypedefItem(ref t) => item_typedef(fmt, self.item, t),
clean::TypedefItem(ref t, _) => item_typedef(fmt, self.item, t),
clean::MacroItem(ref m) => item_macro(fmt, self.item, m),
clean::PrimitiveItem(ref p) => item_primitive(fmt, self.item, p),
clean::StaticItem(ref i) | clean::ForeignStaticItem(ref i) =>
Expand Down Expand Up @@ -2303,10 +2307,10 @@ fn render_deref_methods(w: &mut fmt::Formatter, impl_: &Impl) -> fmt::Result {
let deref_type = impl_.impl_.trait_.as_ref().unwrap();
let target = impl_.impl_.items.iter().filter_map(|item| {
match item.inner {
clean::TypedefItem(ref t) => Some(&t.type_),
clean::TypedefItem(ref t, true) => Some(&t.type_),
_ => None,
}
}).next().unwrap();
}).next().expect("Expected associated type binding");
let what = AssocItemRender::DerefFor { trait_: deref_type, type_: target };
match *target {
clean::ResolvedPath { did, .. } => render_assoc_items(w, did, what),
Expand Down Expand Up @@ -2350,7 +2354,7 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
try!(render_assoc_item(w, item, link));
try!(write!(w, "</code></h4>\n"));
}
clean::TypedefItem(ref tydef) => {
clean::TypedefItem(ref tydef, _) => {
let name = item.name.as_ref().unwrap();
try!(write!(w, "<h4 id='assoc_type.{}' class='{}'><code>",
*name,
Expand Down
10 changes: 10 additions & 0 deletions src/test/rustdoc/search-index.rs
Expand Up @@ -10,6 +10,8 @@

#![crate_name = "rustdoc_test"]

use std::ops::Deref;

// @has search-index.js Foo
pub use private::Foo;

Expand All @@ -24,3 +26,11 @@ mod private {
fn trait_method(&self) {} // @!has - priv_method
}
}

pub struct Bar;

impl Deref for Bar {
// @!has search-index.js Target
type Target = Bar;
fn deref(&self) -> &Bar { self }
}

0 comments on commit 093e18d

Please sign in to comment.