Use Item::is_* methods consistently

This commit is contained in:
mitaa 2016-02-28 12:23:07 +01:00
parent 2a28b69948
commit 032156210d
2 changed files with 26 additions and 22 deletions

View file

@ -175,9 +175,8 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
};
let mut tmp = Vec::new();
for child in &mut m.items {
match child.inner {
ModuleItem(..) => {}
_ => continue,
if !child.is_mod() {
continue;
}
let prim = match PrimitiveType::find(&child.attrs) {
Some(prim) => prim,
@ -272,7 +271,12 @@ impl Item {
pub fn doc_value<'a>(&'a self) -> Option<&'a str> {
self.attrs.value("doc")
}
pub fn is_crate(&self) -> bool {
match self.inner {
ModuleItem(Module { items: _, is_crate: true }) => true,
_ => false
}
}
pub fn is_mod(&self) -> bool {
match self.inner { ModuleItem(..) => true, _ => false }
}
@ -288,6 +292,18 @@ impl Item {
pub fn is_fn(&self) -> bool {
match self.inner { FunctionItem(..) => true, _ => false }
}
pub fn is_associated_type(&self) -> bool {
match self.inner { AssociatedTypeItem(..) => true, _ => false }
}
pub fn is_associated_const(&self) -> bool {
match self.inner { AssociatedConstItem(..) => true, _ => false }
}
pub fn is_method(&self) -> bool {
match self.inner { MethodItem(..) => true, _ => false }
}
pub fn is_ty_method(&self) -> bool {
match self.inner { TyMethodItem(..) => true, _ => false }
}
pub fn stability_class(&self) -> String {
self.stability.as_ref().map(|ref s| {

View file

@ -1266,11 +1266,7 @@ impl Context {
}
title.push_str(" - Rust");
let tyname = shortty(it).to_static_str();
let is_crate = match it.inner {
clean::ModuleItem(clean::Module { items: _, is_crate: true }) => true,
_ => false
};
let desc = if is_crate {
let desc = if it.is_crate() {
format!("API documentation for the Rust `{}` crate.",
cx.layout.krate)
} else {
@ -1891,18 +1887,10 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
bounds,
WhereClause(&t.generics)));
let types = t.items.iter().filter(|m| {
match m.inner { clean::AssociatedTypeItem(..) => true, _ => false }
}).collect::<Vec<_>>();
let consts = t.items.iter().filter(|m| {
match m.inner { clean::AssociatedConstItem(..) => true, _ => false }
}).collect::<Vec<_>>();
let required = t.items.iter().filter(|m| {
match m.inner { clean::TyMethodItem(_) => true, _ => false }
}).collect::<Vec<_>>();
let provided = t.items.iter().filter(|m| {
match m.inner { clean::MethodItem(_) => true, _ => false }
}).collect::<Vec<_>>();
let types = t.items.iter().filter(|m| m.is_associated_type()).collect::<Vec<_>>();
let consts = t.items.iter().filter(|m| m.is_associated_const()).collect::<Vec<_>>();
let required = t.items.iter().filter(|m| m.is_ty_method()).collect::<Vec<_>>();
let provided = t.items.iter().filter(|m| m.is_method()).collect::<Vec<_>>();
if t.items.is_empty() {
try!(write!(w, "{{ }}"));
@ -2600,7 +2588,7 @@ impl<'a> fmt::Display for Sidebar<'a> {
try!(write!(fmt, "</p>"));
// sidebar refers to the enclosing module, not this module
let relpath = if shortty(it) == ItemType::Module { "../" } else { "" };
let relpath = if it.is_mod() { "../" } else { "" };
try!(write!(fmt,
"<script>window.sidebarCurrent = {{\
name: '{name}', \