Skip to content

Commit e32ecee

Browse files
committed
Remove unnecessary CrateNum from Cache.externs
It can be found from ExternalCrate.
1 parent 3e1c75c commit e32ecee

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/librustdoc/clean/types.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ crate struct Crate {
118118
crate name: Symbol,
119119
crate src: FileName,
120120
crate module: Item,
121-
crate externs: Vec<(CrateNum, ExternalCrate)>,
121+
crate externs: Vec<ExternalCrate>,
122122
crate primitives: ThinVec<(DefId, PrimitiveType)>,
123123
// These are later on moved into `CACHEKEY`, leaving the map empty.
124124
// Only here so that they can be filtered through the rustdoc passes.
@@ -133,14 +133,14 @@ crate struct TraitWithExtraInfo {
133133
crate is_notable: bool,
134134
}
135135

136-
#[derive(Clone, Debug)]
136+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
137137
crate struct ExternalCrate {
138138
crate crate_num: CrateNum,
139139
}
140140

141141
impl ExternalCrate {
142142
#[inline]
143-
fn def_id(&self) -> DefId {
143+
crate fn def_id(&self) -> DefId {
144144
DefId { krate: self.crate_num, index: CRATE_DEF_INDEX }
145145
}
146146

src/librustdoc/clean/utils.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::clean::auto_trait::AutoTraitFinder;
22
use crate::clean::blanket_impl::BlanketImplFinder;
33
use crate::clean::{
4-
inline, Clean, Crate, Generic, GenericArg, GenericArgs, ImportSource, Item, ItemKind, Lifetime,
5-
Path, PathSegment, PolyTrait, Primitive, PrimitiveType, ResolvedPath, Type, TypeBinding,
6-
Visibility,
4+
inline, Clean, Crate, ExternalCrate, Generic, GenericArg, GenericArgs, ImportSource, Item,
5+
ItemKind, Lifetime, Path, PathSegment, PolyTrait, Primitive, PrimitiveType, ResolvedPath, Type,
6+
TypeBinding, Visibility,
77
};
88
use crate::core::DocContext;
99
use crate::formats::item_type::ItemType;
@@ -35,11 +35,11 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate {
3535

3636
let mut externs = Vec::new();
3737
for &cnum in cx.tcx.crates(()).iter() {
38-
externs.push((cnum, cnum.clean(cx)));
38+
externs.push(ExternalCrate { crate_num: cnum });
3939
// Analyze doc-reachability for extern items
4040
LibEmbargoVisitor::new(cx).visit_lib(cnum);
4141
}
42-
externs.sort_by(|&(a, _), &(b, _)| a.cmp(&b));
42+
externs.sort_unstable();
4343

4444
// Clean the crate, translating the entire librustc_ast AST to one that is
4545
// understood by rustdoc.

src/librustdoc/formats/cache.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,18 @@ impl Cache {
151151

152152
// Cache where all our extern crates are located
153153
// FIXME: this part is specific to HTML so it'd be nice to remove it from the common code
154-
for &(n, ref e) in &krate.externs {
154+
for &e in &krate.externs {
155155
let name = e.name(tcx);
156156
let extern_url = extern_html_root_urls.get(&*name.as_str()).map(|u| &**u);
157-
let did = DefId { krate: n, index: CRATE_DEF_INDEX };
158-
self.extern_locations.insert(n, e.location(extern_url, &dst, tcx));
159-
self.external_paths.insert(did, (vec![name.to_string()], ItemType::Module));
157+
self.extern_locations.insert(e.crate_num, e.location(extern_url, &dst, tcx));
158+
self.external_paths.insert(e.def_id(), (vec![name.to_string()], ItemType::Module));
160159
}
161160

162161
// Cache where all known primitives have their documentation located.
163162
//
164163
// Favor linking to as local extern as possible, so iterate all crates in
165164
// reverse topological order.
166-
for &(_, ref e) in krate.externs.iter().rev() {
165+
for &e in krate.externs.iter().rev() {
167166
for &(def_id, prim) in &e.primitives(tcx) {
168167
self.primitive_locations.insert(prim, def_id);
169168
}

0 commit comments

Comments
 (0)