Skip to content

Commit c66c453

Browse files
committed
Migrate Item ➡ ItemType function to method.
1 parent ea65ab6 commit c66c453

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -283,34 +283,34 @@ impl Item {
283283
}
284284
}
285285
pub fn is_mod(&self) -> bool {
286-
ItemType::from(self) == ItemType::Module
286+
self.type_() == ItemType::Module
287287
}
288288
pub fn is_trait(&self) -> bool {
289-
ItemType::from(self) == ItemType::Trait
289+
self.type_() == ItemType::Trait
290290
}
291291
pub fn is_struct(&self) -> bool {
292-
ItemType::from(self) == ItemType::Struct
292+
self.type_() == ItemType::Struct
293293
}
294294
pub fn is_enum(&self) -> bool {
295-
ItemType::from(self) == ItemType::Module
295+
self.type_() == ItemType::Module
296296
}
297297
pub fn is_fn(&self) -> bool {
298-
ItemType::from(self) == ItemType::Function
298+
self.type_() == ItemType::Function
299299
}
300300
pub fn is_associated_type(&self) -> bool {
301-
ItemType::from(self) == ItemType::AssociatedType
301+
self.type_() == ItemType::AssociatedType
302302
}
303303
pub fn is_associated_const(&self) -> bool {
304-
ItemType::from(self) == ItemType::AssociatedConst
304+
self.type_() == ItemType::AssociatedConst
305305
}
306306
pub fn is_method(&self) -> bool {
307-
ItemType::from(self) == ItemType::Method
307+
self.type_() == ItemType::Method
308308
}
309309
pub fn is_ty_method(&self) -> bool {
310-
ItemType::from(self) == ItemType::TyMethod
310+
self.type_() == ItemType::TyMethod
311311
}
312312
pub fn is_primitive(&self) -> bool {
313-
ItemType::from(self) == ItemType::Primitive
313+
self.type_() == ItemType::Primitive
314314
}
315315
pub fn is_stripped(&self) -> bool {
316316
match self.inner { StrippedItem(..) => true, _ => false }
@@ -342,6 +342,11 @@ impl Item {
342342
pub fn stable_since(&self) -> Option<&str> {
343343
self.stability.as_ref().map(|s| &s.since[..])
344344
}
345+
346+
/// Returns a documentation-level item type from the item.
347+
pub fn type_(&self) -> ItemType {
348+
ItemType::from(self)
349+
}
345350
}
346351

347352
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]

src/librustdoc/html/render.rs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
591591
for &(did, ref item) in orphan_impl_items {
592592
if let Some(&(ref fqp, _)) = paths.get(&did) {
593593
search_index.push(IndexItem {
594-
ty: item_type(item),
594+
ty: item.type_(),
595595
name: item.name.clone().unwrap(),
596596
path: fqp[..fqp.len() - 1].join("::"),
597597
desc: Escape(&shorter(item.doc_value())).to_string(),
@@ -835,11 +835,6 @@ fn mkdir(path: &Path) -> io::Result<()> {
835835
}
836836
}
837837

838-
/// Returns a documentation-level item type from the item.
839-
fn item_type(item: &clean::Item) -> ItemType {
840-
ItemType::from(item)
841-
}
842-
843838
/// Takes a path to a source file and cleans the path to it. This canonicalizes
844839
/// things like ".." to components which preserve the "top down" hierarchy of a
845840
/// static HTML tree. Each component in the cleaned path will be passed as an
@@ -1075,7 +1070,7 @@ impl DocFolder for Cache {
10751070
// inserted later on when serializing the search-index.
10761071
if item.def_id.index != CRATE_DEF_INDEX {
10771072
self.search_index.push(IndexItem {
1078-
ty: item_type(&item),
1073+
ty: item.type_(),
10791074
name: s.to_string(),
10801075
path: path.join("::").to_string(),
10811076
desc: Escape(&shorter(item.doc_value())).to_string(),
@@ -1122,7 +1117,7 @@ impl DocFolder for Cache {
11221117
self.access_levels.is_public(item.def_id)
11231118
{
11241119
self.paths.insert(item.def_id,
1125-
(self.stack.clone(), item_type(&item)));
1120+
(self.stack.clone(), item.type_()));
11261121
}
11271122
}
11281123
// link variants to their parent enum because pages aren't emitted
@@ -1135,7 +1130,7 @@ impl DocFolder for Cache {
11351130

11361131
clean::PrimitiveItem(..) if item.visibility.is_some() => {
11371132
self.paths.insert(item.def_id, (self.stack.clone(),
1138-
item_type(&item)));
1133+
item.type_()));
11391134
}
11401135

11411136
_ => {}
@@ -1304,7 +1299,7 @@ impl Context {
13041299
title.push_str(it.name.as_ref().unwrap());
13051300
}
13061301
title.push_str(" - Rust");
1307-
let tyname = item_type(it).css_class();
1302+
let tyname = it.type_().css_class();
13081303
let desc = if it.is_crate() {
13091304
format!("API documentation for the Rust `{}` crate.",
13101305
self.shared.layout.krate)
@@ -1407,7 +1402,7 @@ impl Context {
14071402
// buf will be empty if the item is stripped and there is no redirect for it
14081403
if !buf.is_empty() {
14091404
let name = item.name.as_ref().unwrap();
1410-
let item_type = item_type(&item);
1405+
let item_type = item.type_();
14111406
let file_name = &item_path(item_type, name);
14121407
let joint_dst = self.dst.join(file_name);
14131408
try_err!(fs::create_dir_all(&self.dst), &self.dst);
@@ -1444,7 +1439,7 @@ impl Context {
14441439
for item in &m.items {
14451440
if maybe_ignore_item(item) { continue }
14461441

1447-
let short = item_type(item).css_class();
1442+
let short = item.type_().css_class();
14481443
let myname = match item.name {
14491444
None => continue,
14501445
Some(ref s) => s.to_string(),
@@ -1541,7 +1536,7 @@ impl<'a> Item<'a> {
15411536
}
15421537
Some(format!("{path}{file}?gotosrc={goto}",
15431538
path = path,
1544-
file = item_path(item_type(self.item), external_path.last().unwrap()),
1539+
file = item_path(self.item.type_(), external_path.last().unwrap()),
15451540
goto = self.item.def_id.index.as_usize()))
15461541
}
15471542
}
@@ -1586,7 +1581,7 @@ impl<'a> fmt::Display for Item<'a> {
15861581
}
15871582
}
15881583
write!(fmt, "<a class='{}' href=''>{}</a>",
1589-
item_type(self.item), self.item.name.as_ref().unwrap())?;
1584+
self.item.type_(), self.item.name.as_ref().unwrap())?;
15901585

15911586
write!(fmt, "</span>")?; // in-band
15921587
write!(fmt, "<span class='out-of-band'>")?;
@@ -1739,8 +1734,8 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
17391734
}
17401735

17411736
fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: usize, idx2: usize) -> Ordering {
1742-
let ty1 = item_type(i1);
1743-
let ty2 = item_type(i2);
1737+
let ty1 = i1.type_();
1738+
let ty2 = i2.type_();
17441739
if ty1 != ty2 {
17451740
return (reorder(ty1), idx1).cmp(&(reorder(ty2), idx2))
17461741
}
@@ -1764,7 +1759,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
17641759
continue;
17651760
}
17661761

1767-
let myty = Some(item_type(myitem));
1762+
let myty = Some(myitem.type_());
17681763
if curty == Some(ItemType::ExternCrate) && myty == Some(ItemType::Import) {
17691764
// Put `extern crate` and `use` re-exports in the same section.
17701765
curty = myty;
@@ -1851,9 +1846,9 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
18511846
name = *myitem.name.as_ref().unwrap(),
18521847
stab_docs = stab_docs,
18531848
docs = shorter(Some(&Markdown(doc_value).to_string())),
1854-
class = item_type(myitem),
1849+
class = myitem.type_(),
18551850
stab = myitem.stability_class(),
1856-
href = item_path(item_type(myitem), myitem.name.as_ref().unwrap()),
1851+
href = item_path(myitem.type_(), myitem.name.as_ref().unwrap()),
18571852
title = full_path(cx, myitem))?;
18581853
}
18591854
}
@@ -2059,7 +2054,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
20592054
fn trait_item(w: &mut fmt::Formatter, cx: &Context, m: &clean::Item, t: &clean::Item)
20602055
-> fmt::Result {
20612056
let name = m.name.as_ref().unwrap();
2062-
let item_type = item_type(m);
2057+
let item_type = m.type_();
20632058
let id = derive_id(format!("{}.{}", item_type, name));
20642059
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
20652060
write!(w, "<h3 id='{id}' class='method stab {stab}'>\
@@ -2145,7 +2140,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
21452140
let (ref path, _) = cache.external_paths[&it.def_id];
21462141
path[..path.len() - 1].join("/")
21472142
},
2148-
ty = item_type(it).css_class(),
2143+
ty = it.type_().css_class(),
21492144
name = *it.name.as_ref().unwrap())?;
21502145
Ok(())
21512146
}
@@ -2154,7 +2149,7 @@ fn naive_assoc_href(it: &clean::Item, link: AssocItemLink) -> String {
21542149
use html::item_type::ItemType::*;
21552150

21562151
let name = it.name.as_ref().unwrap();
2157-
let ty = match item_type(it) {
2152+
let ty = match it.type_() {
21582153
Typedef | AssociatedType => AssociatedType,
21592154
s@_ => s,
21602155
};
@@ -2232,7 +2227,7 @@ fn render_assoc_item(w: &mut fmt::Formatter,
22322227
link: AssocItemLink)
22332228
-> fmt::Result {
22342229
let name = meth.name.as_ref().unwrap();
2235-
let anchor = format!("#{}.{}", item_type(meth), name);
2230+
let anchor = format!("#{}.{}", meth.type_(), name);
22362231
let href = match link {
22372232
AssocItemLink::Anchor(Some(ref id)) => format!("#{}", id),
22382233
AssocItemLink::Anchor(None) => anchor,
@@ -2740,7 +2735,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
27402735
link: AssocItemLink, render_mode: RenderMode,
27412736
is_default_item: bool, outer_version: Option<&str>,
27422737
trait_: Option<&clean::Trait>) -> fmt::Result {
2743-
let item_type = item_type(item);
2738+
let item_type = item.type_();
27442739
let name = item.name.as_ref().unwrap();
27452740

27462741
let render_method_item: bool = match render_mode {
@@ -2932,7 +2927,7 @@ impl<'a> fmt::Display for Sidebar<'a> {
29322927
relpath: '{path}'\
29332928
}};</script>",
29342929
name = it.name.as_ref().map(|x| &x[..]).unwrap_or(""),
2935-
ty = item_type(it).css_class(),
2930+
ty = it.type_().css_class(),
29362931
path = relpath)?;
29372932
if parentlen == 0 {
29382933
// there is no sidebar-items.js beyond the crate root path

0 commit comments

Comments
 (0)