Skip to content

Commit b419a1d

Browse files
Remove "primitive_locations" field from Cache
1 parent 054e3bf commit b419a1d

File tree

3 files changed

+14
-29
lines changed

3 files changed

+14
-29
lines changed

src/librustdoc/formats/cache.rs

+5-23
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
99
use rustc_middle::middle::privacy::AccessLevels;
1010
use rustc_span::source_map::FileName;
1111

12-
use crate::clean::{self, GetDefId};
12+
use crate::clean::{self, primitives, GetDefId};
1313
use crate::config::RenderInfo;
1414
use crate::fold::DocFolder;
1515
use crate::formats::item_type::ItemType;
@@ -76,9 +76,6 @@ pub struct Cache {
7676
/// Cache of where external crate documentation can be found.
7777
pub extern_locations: FxHashMap<CrateNum, (String, PathBuf, ExternalLocation)>,
7878

79-
/// Cache of where documentation for primitives can be found.
80-
pub primitive_locations: FxHashMap<clean::PrimitiveType, DefId>,
81-
8279
// Note that external items for which `doc(hidden)` applies to are shown as
8380
// non-reachable while local items aren't. This is because we're reusing
8481
// the access levels from the privacy check pass.
@@ -182,19 +179,6 @@ impl Cache {
182179
cache.external_paths.insert(did, (vec![e.name.to_string()], ItemType::Module));
183180
}
184181

185-
// Cache where all known primitives have their documentation located.
186-
//
187-
// Favor linking to as local extern as possible, so iterate all crates in
188-
// reverse topological order.
189-
for &(_, ref e) in krate.externs.iter().rev() {
190-
for &(def_id, prim, _) in &e.primitives {
191-
cache.primitive_locations.insert(prim, def_id);
192-
}
193-
}
194-
for &(def_id, prim, _) in &krate.primitives {
195-
cache.primitive_locations.insert(prim, def_id);
196-
}
197-
198182
cache.stack.push(krate.name.clone());
199183
krate = cache.fold_crate(krate);
200184

@@ -403,9 +387,8 @@ impl DocFolder for Cache {
403387
true
404388
}
405389
ref t => {
406-
let prim_did = t
407-
.primitive_type()
408-
.and_then(|t| self.primitive_locations.get(&t).cloned());
390+
let prim_did =
391+
t.primitive_type().and_then(|t| primitives().get(&t).cloned());
409392
match prim_did {
410393
Some(did) => {
411394
self.parent_stack.push(did);
@@ -436,9 +419,8 @@ impl DocFolder for Cache {
436419
dids.insert(did);
437420
}
438421
ref t => {
439-
let did = t
440-
.primitive_type()
441-
.and_then(|t| self.primitive_locations.get(&t).cloned());
422+
let did =
423+
t.primitive_type().and_then(|t| primitives().get(&t).cloned());
442424

443425
if let Some(did) = did {
444426
dids.insert(did);

src/librustdoc/html/format.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_hir as hir;
1414
use rustc_span::def_id::DefId;
1515
use rustc_target::spec::abi::Abi;
1616

17-
use crate::clean::{self, PrimitiveType};
17+
use crate::clean::{self, primitives, PrimitiveType};
1818
use crate::formats::cache::cache;
1919
use crate::formats::item_type::ItemType;
2020
use crate::html::escape::Escape;
@@ -559,10 +559,13 @@ fn primitive_link(
559559
prim: clean::PrimitiveType,
560560
name: &str,
561561
) -> fmt::Result {
562-
let m = cache();
563562
let mut needs_termination = false;
563+
564564
if !f.alternate() {
565-
match m.primitive_locations.get(&prim) {
565+
let m = cache();
566+
let primitives = primitives();
567+
568+
match primitives.get(&prim) {
566569
Some(&def_id) if def_id.is_local() => {
567570
let len = CURRENT_DEPTH.with(|s| s.get());
568571
let len = if len == 0 { 0 } else { len - 1 };

src/librustdoc/html/render/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use rustc_span::symbol::{sym, Symbol};
6363
use serde::ser::SerializeSeq;
6464
use serde::{Serialize, Serializer};
6565

66-
use crate::clean::{self, AttributesExt, Deprecation, GetDefId, SelfTy, TypeKind};
66+
use crate::clean::{self, primitives, AttributesExt, Deprecation, GetDefId, SelfTy, TypeKind};
6767
use crate::config::RenderInfo;
6868
use crate::config::RenderOptions;
6969
use crate::docfs::{DocFS, PathError};
@@ -3405,7 +3405,7 @@ fn render_deref_methods(
34053405
render_assoc_items(w, cx, container_item, did, what, cache);
34063406
} else {
34073407
if let Some(prim) = target.primitive_type() {
3408-
if let Some(&did) = cache.primitive_locations.get(&prim) {
3408+
if let Some(&did) = primitives().get(&prim) {
34093409
render_assoc_items(w, cx, container_item, did, what, cache);
34103410
}
34113411
}
@@ -4058,7 +4058,7 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
40584058
.def_id()
40594059
.or(target
40604060
.primitive_type()
4061-
.and_then(|prim| c.primitive_locations.get(&prim).cloned()))
4061+
.and_then(|prim| primitives().get(&prim).cloned()))
40624062
.and_then(|did| c.impls.get(&did));
40634063
if let Some(impls) = inner_impl {
40644064
out.push_str("<a class=\"sidebar-title\" href=\"#deref-methods\">");

0 commit comments

Comments
 (0)