Skip to content

Commit 0321562

Browse files
committed
Use Item::is_* methods consistently
1 parent 2a28b69 commit 0321562

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

src/librustdoc/clean/mod.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,8 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
175175
};
176176
let mut tmp = Vec::new();
177177
for child in &mut m.items {
178-
match child.inner {
179-
ModuleItem(..) => {}
180-
_ => continue,
178+
if !child.is_mod() {
179+
continue;
181180
}
182181
let prim = match PrimitiveType::find(&child.attrs) {
183182
Some(prim) => prim,
@@ -272,7 +271,12 @@ impl Item {
272271
pub fn doc_value<'a>(&'a self) -> Option<&'a str> {
273272
self.attrs.value("doc")
274273
}
275-
274+
pub fn is_crate(&self) -> bool {
275+
match self.inner {
276+
ModuleItem(Module { items: _, is_crate: true }) => true,
277+
_ => false
278+
}
279+
}
276280
pub fn is_mod(&self) -> bool {
277281
match self.inner { ModuleItem(..) => true, _ => false }
278282
}
@@ -288,6 +292,18 @@ impl Item {
288292
pub fn is_fn(&self) -> bool {
289293
match self.inner { FunctionItem(..) => true, _ => false }
290294
}
295+
pub fn is_associated_type(&self) -> bool {
296+
match self.inner { AssociatedTypeItem(..) => true, _ => false }
297+
}
298+
pub fn is_associated_const(&self) -> bool {
299+
match self.inner { AssociatedConstItem(..) => true, _ => false }
300+
}
301+
pub fn is_method(&self) -> bool {
302+
match self.inner { MethodItem(..) => true, _ => false }
303+
}
304+
pub fn is_ty_method(&self) -> bool {
305+
match self.inner { TyMethodItem(..) => true, _ => false }
306+
}
291307

292308
pub fn stability_class(&self) -> String {
293309
self.stability.as_ref().map(|ref s| {

src/librustdoc/html/render.rs

+6-18
Original file line numberDiff line numberDiff line change
@@ -1266,11 +1266,7 @@ impl Context {
12661266
}
12671267
title.push_str(" - Rust");
12681268
let tyname = shortty(it).to_static_str();
1269-
let is_crate = match it.inner {
1270-
clean::ModuleItem(clean::Module { items: _, is_crate: true }) => true,
1271-
_ => false
1272-
};
1273-
let desc = if is_crate {
1269+
let desc = if it.is_crate() {
12741270
format!("API documentation for the Rust `{}` crate.",
12751271
cx.layout.krate)
12761272
} else {
@@ -1891,18 +1887,10 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
18911887
bounds,
18921888
WhereClause(&t.generics)));
18931889

1894-
let types = t.items.iter().filter(|m| {
1895-
match m.inner { clean::AssociatedTypeItem(..) => true, _ => false }
1896-
}).collect::<Vec<_>>();
1897-
let consts = t.items.iter().filter(|m| {
1898-
match m.inner { clean::AssociatedConstItem(..) => true, _ => false }
1899-
}).collect::<Vec<_>>();
1900-
let required = t.items.iter().filter(|m| {
1901-
match m.inner { clean::TyMethodItem(_) => true, _ => false }
1902-
}).collect::<Vec<_>>();
1903-
let provided = t.items.iter().filter(|m| {
1904-
match m.inner { clean::MethodItem(_) => true, _ => false }
1905-
}).collect::<Vec<_>>();
1890+
let types = t.items.iter().filter(|m| m.is_associated_type()).collect::<Vec<_>>();
1891+
let consts = t.items.iter().filter(|m| m.is_associated_const()).collect::<Vec<_>>();
1892+
let required = t.items.iter().filter(|m| m.is_ty_method()).collect::<Vec<_>>();
1893+
let provided = t.items.iter().filter(|m| m.is_method()).collect::<Vec<_>>();
19061894

19071895
if t.items.is_empty() {
19081896
try!(write!(w, "{{ }}"));
@@ -2600,7 +2588,7 @@ impl<'a> fmt::Display for Sidebar<'a> {
26002588
try!(write!(fmt, "</p>"));
26012589

26022590
// sidebar refers to the enclosing module, not this module
2603-
let relpath = if shortty(it) == ItemType::Module { "../" } else { "" };
2591+
let relpath = if it.is_mod() { "../" } else { "" };
26042592
try!(write!(fmt,
26052593
"<script>window.sidebarCurrent = {{\
26062594
name: '{name}', \

0 commit comments

Comments
 (0)