diff options
| author | mitaa <mitaa.ceb@gmail.com> | 2016-02-28 12:23:07 +0100 |
|---|---|---|
| committer | mitaa <mitaa.ceb@gmail.com> | 2016-03-04 19:40:00 +0100 |
| commit | 032156210deaf71fddc4f8577fa2b541606ed547 (patch) | |
| tree | bc2a785d7ba19e776e5298e90ae333f5d5f4fa0d | |
| parent | 2a28b69948e13ec09a8a7701fa4d9001e880ad5f (diff) | |
| download | rust-032156210deaf71fddc4f8577fa2b541606ed547.tar.gz rust-032156210deaf71fddc4f8577fa2b541606ed547.zip | |
Use `Item::is_*` methods consistently
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 24 | ||||
| -rw-r--r-- | src/librustdoc/html/render.rs | 24 |
2 files changed, 26 insertions, 22 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 20bcf759cf7..c2a37a555d6 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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| { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index f1d83690079..88f21b67a5a 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -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}', \ |
