Move ItemEnum → Generics logic into method on ItemEnum.

This commit is contained in:
Corey Farwell 2016-08-20 13:36:52 -04:00
parent 012f45eaf7
commit 28ecfb691d
2 changed files with 19 additions and 11 deletions

View File

@ -380,6 +380,23 @@ pub enum ItemEnum {
StrippedItem(Box<ItemEnum>),
}
impl ItemEnum {
pub fn generics(&self) -> Option<&Generics> {
Some(match *self {
ItemEnum::StructItem(ref s) => &s.generics,
ItemEnum::EnumItem(ref e) => &e.generics,
ItemEnum::FunctionItem(ref f) => &f.generics,
ItemEnum::TypedefItem(ref t, _) => &t.generics,
ItemEnum::TraitItem(ref t) => &t.generics,
ItemEnum::ImplItem(ref i) => &i.generics,
ItemEnum::TyMethodItem(ref i) => &i.generics,
ItemEnum::MethodItem(ref i) => &i.generics,
ItemEnum::ForeignFunctionItem(ref f) => &f.generics,
_ => return None,
})
}
}
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Module {
pub items: Vec<Item>,

View File

@ -997,17 +997,8 @@ impl DocFolder for Cache {
// Register any generics to their corresponding string. This is used
// when pretty-printing types
match item.inner {
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::TraitItem(ref t) => self.generics(&t.generics),
clean::ImplItem(ref i) => self.generics(&i.generics),
clean::TyMethodItem(ref i) => self.generics(&i.generics),
clean::MethodItem(ref i) => self.generics(&i.generics),
clean::ForeignFunctionItem(ref f) => self.generics(&f.generics),
_ => {}
if let Some(generics) = item.inner.generics() {
self.generics(generics);
}
if !self.seen_mod {