Skip to content

Commit e3e8087

Browse files
committed
Use from_def_id_and_parts for primitives and keywords
- Take `String` instead of `Symbol` - this avoids having to intern then immediately stringify the existing string. - Remove unused `get_stability` and `get_deprecation` - Remove unused `attrs` field from `primitives`
1 parent f8b3a28 commit e3e8087

File tree

5 files changed

+35
-44
lines changed

5 files changed

+35
-44
lines changed

src/librustdoc/clean/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ crate fn try_inline(
124124
let attrs = merge_attrs(cx, Some(parent_module), target_attrs, attrs_clone);
125125

126126
cx.renderinfo.borrow_mut().inlined.insert(did);
127-
let what_rustc_thinks = clean::Item::from_def_id_and_parts(did, Some(name), kind, cx);
127+
let what_rustc_thinks = clean::Item::from_def_id_and_parts(did, Some(name.clean(cx)), kind, cx);
128128
ret.push(clean::Item { attrs, ..what_rustc_thinks });
129129
Some(ret)
130130
}

src/librustdoc/clean/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl Clean<ExternalCrate> for CrateNum {
122122
}
123123
}
124124
}
125-
return prim.map(|p| (def_id, p, attrs));
125+
return prim.map(|p| (def_id, p));
126126
}
127127
None
128128
};
@@ -144,9 +144,9 @@ impl Clean<ExternalCrate> for CrateNum {
144144
hir::ItemKind::Use(ref path, hir::UseKind::Single)
145145
if item.vis.node.is_pub() =>
146146
{
147-
as_primitive(path.res).map(|(_, prim, attrs)| {
147+
as_primitive(path.res).map(|(_, prim)| {
148148
// Pretend the primitive is local.
149-
(cx.tcx.hir().local_def_id(id.id).to_def_id(), prim, attrs)
149+
(cx.tcx.hir().local_def_id(id.id).to_def_id(), prim)
150150
})
151151
}
152152
_ => None,
@@ -1099,7 +1099,7 @@ impl Clean<Item> for hir::TraitItem<'_> {
10991099
AssocTypeItem(bounds.clean(cx), default.clean(cx))
11001100
}
11011101
};
1102-
Item::from_def_id_and_parts(local_did, Some(self.ident.name), inner, cx)
1102+
Item::from_def_id_and_parts(local_did, Some(self.ident.name.clean(cx)), inner, cx)
11031103
})
11041104
}
11051105
}
@@ -1127,7 +1127,7 @@ impl Clean<Item> for hir::ImplItem<'_> {
11271127
TypedefItem(Typedef { type_, generics: Generics::default(), item_type }, true)
11281128
}
11291129
};
1130-
Item::from_def_id_and_parts(local_did, Some(self.ident.name), inner, cx)
1130+
Item::from_def_id_and_parts(local_did, Some(self.ident.name.clean(cx)), inner, cx)
11311131
})
11321132
}
11331133
}
@@ -1284,7 +1284,7 @@ impl Clean<Item> for ty::AssocItem {
12841284
}
12851285
};
12861286

1287-
Item::from_def_id_and_parts(self.def_id, Some(self.ident.name), kind, cx)
1287+
Item::from_def_id_and_parts(self.def_id, Some(self.ident.name.clean(cx)), kind, cx)
12881288
}
12891289
}
12901290

@@ -1769,7 +1769,7 @@ impl Clean<Item> for ty::FieldDef {
17691769
fn clean(&self, cx: &DocContext<'_>) -> Item {
17701770
let what_rustc_thinks = Item::from_def_id_and_parts(
17711771
self.did,
1772-
Some(self.ident.name),
1772+
Some(self.ident.name.clean(cx)),
17731773
StructFieldItem(cx.tcx.type_of(self.did).clean(cx)),
17741774
cx,
17751775
);
@@ -1845,7 +1845,7 @@ impl Clean<Item> for ty::VariantDef {
18451845
.fields
18461846
.iter()
18471847
.map(|field| {
1848-
let name = Some(field.ident.name);
1848+
let name = Some(field.ident.name.clean(cx));
18491849
let kind = StructFieldItem(cx.tcx.type_of(field.did).clean(cx));
18501850
let what_rustc_thinks =
18511851
Item::from_def_id_and_parts(field.did, name, kind, cx);
@@ -1857,7 +1857,7 @@ impl Clean<Item> for ty::VariantDef {
18571857
};
18581858
let what_rustc_thinks = Item::from_def_id_and_parts(
18591859
self.def_id,
1860-
Some(self.ident.name),
1860+
Some(self.ident.name.clean(cx)),
18611861
VariantItem(Variant { kind }),
18621862
cx,
18631863
);
@@ -2055,7 +2055,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Ident>) {
20552055
_ => unreachable!("not yet converted"),
20562056
};
20572057

2058-
vec![Item::from_def_id_and_parts(def_id, Some(name), kind, cx)]
2058+
vec![Item::from_def_id_and_parts(def_id, Some(name.clean(cx)), kind, cx)]
20592059
})
20602060
}
20612061
}
@@ -2317,7 +2317,7 @@ impl Clean<Item> for doctree::Macro {
23172317
fn clean(&self, cx: &DocContext<'_>) -> Item {
23182318
Item::from_def_id_and_parts(
23192319
self.def_id,
2320-
Some(self.name),
2320+
Some(self.name.clean(cx)),
23212321
MacroItem(Macro {
23222322
source: format!(
23232323
"macro_rules! {} {{\n{}}}",

src/librustdoc/clean/types.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use smallvec::{smallvec, SmallVec};
3333
use crate::clean::cfg::Cfg;
3434
use crate::clean::external_path;
3535
use crate::clean::inline;
36+
use crate::clean::Clean;
3637
use crate::clean::types::Type::{QPath, ResolvedPath};
3738
use crate::core::DocContext;
3839
use crate::doctree;
@@ -54,7 +55,7 @@ crate struct Crate {
5455
crate src: FileName,
5556
crate module: Option<Item>,
5657
crate externs: Vec<(CrateNum, ExternalCrate)>,
57-
crate primitives: Vec<(DefId, PrimitiveType, Attributes)>,
58+
crate primitives: Vec<(DefId, PrimitiveType)>,
5859
// These are later on moved into `CACHEKEY`, leaving the map empty.
5960
// Only here so that they can be filtered through the rustdoc passes.
6061
crate external_traits: Rc<RefCell<FxHashMap<DefId, Trait>>>,
@@ -67,7 +68,7 @@ crate struct ExternalCrate {
6768
crate name: String,
6869
crate src: FileName,
6970
crate attrs: Attributes,
70-
crate primitives: Vec<(DefId, PrimitiveType, Attributes)>,
71+
crate primitives: Vec<(DefId, PrimitiveType)>,
7172
crate keywords: Vec<(DefId, String, Attributes)>,
7273
}
7374

@@ -120,17 +121,15 @@ impl Item {
120121
kind: ItemKind,
121122
cx: &DocContext<'_>,
122123
) -> Item {
123-
Item::from_def_id_and_parts(cx.tcx.hir().local_def_id(hir_id).to_def_id(), name, kind, cx)
124+
Item::from_def_id_and_parts(cx.tcx.hir().local_def_id(hir_id).to_def_id(), name.clean(cx), kind, cx)
124125
}
125126

126127
pub fn from_def_id_and_parts(
127128
def_id: DefId,
128-
name: Option<Symbol>,
129+
name: Option<String>,
129130
kind: ItemKind,
130131
cx: &DocContext<'_>,
131132
) -> Item {
132-
use super::Clean;
133-
134133
debug!("name={:?}, def_id={:?}", name, def_id);
135134

136135
// `span_if_local()` lies about functions and only gives the span of the function signature
@@ -145,7 +144,7 @@ impl Item {
145144
Item {
146145
def_id,
147146
kind,
148-
name: name.clean(cx),
147+
name,
149148
source: source.clean(cx),
150149
attrs: cx.tcx.get_attrs(def_id).clean(cx),
151150
visibility: cx.tcx.visibility(def_id).clean(cx),

src/librustdoc/clean/utils.rs

+15-23
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
use crate::clean::auto_trait::AutoTraitFinder;
22
use crate::clean::blanket_impl::BlanketImplFinder;
33
use crate::clean::{
4-
inline, Clean, Crate, Deprecation, ExternalCrate, FnDecl, FnRetTy, Generic, GenericArg,
4+
inline, Clean, Crate, ExternalCrate, FnDecl, FnRetTy, Generic, GenericArg,
55
GenericArgs, GenericBound, Generics, GetDefId, ImportSource, Item, ItemKind, Lifetime,
6-
MacroKind, Path, PathSegment, Primitive, PrimitiveType, ResolvedPath, Span, Type, TypeBinding,
7-
TypeKind, Visibility, WherePredicate,
6+
MacroKind, Path, PathSegment, Primitive, PrimitiveType, ResolvedPath, Type, TypeBinding,
7+
TypeKind, WherePredicate,
88
};
99
use crate::core::DocContext;
1010

1111
use itertools::Itertools;
12-
use rustc_attr::Stability;
1312
use rustc_data_structures::fx::FxHashSet;
1413
use rustc_hir as hir;
1514
use rustc_hir::def::{DefKind, Res};
@@ -66,17 +65,18 @@ crate fn krate(mut cx: &mut DocContext<'_>) -> Crate {
6665
ItemKind::ModuleItem(ref mut m) => m,
6766
_ => unreachable!(),
6867
};
69-
m.items.extend(primitives.iter().map(|&(def_id, prim, ref attrs)| Item {
70-
source: Span::empty(),
71-
name: Some(prim.to_url_str().to_string()),
72-
attrs: attrs.clone(),
73-
visibility: Visibility::Public,
74-
stability: get_stability(cx, def_id),
75-
deprecation: get_deprecation(cx, def_id),
76-
def_id,
77-
kind: ItemKind::PrimitiveItem(prim),
68+
m.items.extend(primitives.iter().map(|&(def_id, prim)| {
69+
Item::from_def_id_and_parts(
70+
def_id,
71+
Some(prim.to_url_str().to_owned()),
72+
ItemKind::PrimitiveItem(prim),
73+
cx,
74+
)
7875
}));
79-
m.items.extend(keywords.into_iter().map(|(def_id, kw, attrs)| Item {
76+
m.items.extend(keywords.into_iter()
77+
.map(|(def_id, kw, _)| Item::from_def_id_and_parts(def_id, Some(kw.clone()), ItemKind::KeywordItem(kw), cx)
78+
));
79+
/*
8080
source: Span::empty(),
8181
name: Some(kw.clone()),
8282
attrs,
@@ -86,6 +86,7 @@ crate fn krate(mut cx: &mut DocContext<'_>) -> Crate {
8686
def_id,
8787
kind: ItemKind::KeywordItem(kw),
8888
}));
89+
*/
8990
}
9091

9192
Crate {
@@ -101,15 +102,6 @@ crate fn krate(mut cx: &mut DocContext<'_>) -> Crate {
101102
}
102103
}
103104

104-
// extract the stability index for a node from tcx, if possible
105-
crate fn get_stability(cx: &DocContext<'_>, def_id: DefId) -> Option<Stability> {
106-
cx.tcx.lookup_stability(def_id).cloned()
107-
}
108-
109-
crate fn get_deprecation(cx: &DocContext<'_>, def_id: DefId) -> Option<Deprecation> {
110-
cx.tcx.lookup_deprecation(def_id).clean(cx)
111-
}
112-
113105
fn external_generic_args(
114106
cx: &DocContext<'_>,
115107
trait_did: Option<DefId>,

src/librustdoc/formats/cache.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ impl Cache {
187187
// Favor linking to as local extern as possible, so iterate all crates in
188188
// reverse topological order.
189189
for &(_, ref e) in krate.externs.iter().rev() {
190-
for &(def_id, prim, _) in &e.primitives {
190+
for &(def_id, prim) in &e.primitives {
191191
cache.primitive_locations.insert(prim, def_id);
192192
}
193193
}
194-
for &(def_id, prim, _) in &krate.primitives {
194+
for &(def_id, prim) in &krate.primitives {
195195
cache.primitive_locations.insert(prim, def_id);
196196
}
197197

0 commit comments

Comments
 (0)