Skip to content

Commit 7499e21

Browse files
rustdoc-json: discard non-local inherent impls
1 parent 80d8270 commit 7499e21

File tree

3 files changed

+20
-29
lines changed

3 files changed

+20
-29
lines changed

src/librustdoc/formats/cache.rs

+15-23
Original file line numberDiff line numberDiff line change
@@ -442,16 +442,16 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
442442
// `public_items` map, so we can skip inserting into the
443443
// paths map if there was already an entry present and we're
444444
// not a public item.
445-
if !self.cache.paths.contains_key(&item.item_id.expect_def_id())
445+
let item_def_id = item.item_id.expect_def_id();
446+
if !self.cache.paths.contains_key(&item_def_id)
446447
|| self
447448
.cache
448449
.effective_visibilities
449-
.is_directly_public(self.tcx, item.item_id.expect_def_id())
450+
.is_directly_public(self.tcx, item_def_id)
450451
{
451-
self.cache.paths.insert(
452-
item.item_id.expect_def_id(),
453-
(self.cache.stack.clone(), item.type_()),
454-
);
452+
self.cache
453+
.paths
454+
.insert(item_def_id, (self.cache.stack.clone(), item.type_()));
455455
}
456456
}
457457
}
@@ -514,9 +514,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
514514
&& adt.is_fundamental()
515515
{
516516
for ty in generics {
517-
if let Some(did) = ty.def_id(self.cache) {
518-
dids.insert(did);
519-
}
517+
dids.extend(ty.def_id(self.cache));
520518
}
521519
}
522520
}
@@ -529,32 +527,26 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
529527
.primitive_type()
530528
.and_then(|t| self.cache.primitive_locations.get(&t).cloned());
531529

532-
if let Some(did) = did {
533-
dids.insert(did);
534-
}
530+
dids.extend(did);
535531
}
536532
}
537533

538534
if let Some(generics) = i.trait_.as_ref().and_then(|t| t.generics()) {
539535
for bound in generics {
540-
if let Some(did) = bound.def_id(self.cache) {
541-
dids.insert(did);
542-
}
536+
dids.extend(bound.def_id(self.cache));
543537
}
544538
}
545539
let impl_item = Impl { impl_item: item };
546-
if impl_item.trait_did().map_or(true, |d| self.cache.traits.contains_key(&d)) {
540+
let impl_did = impl_item.def_id();
541+
let trait_did = impl_item.trait_did();
542+
if trait_did.map_or(true, |d| self.cache.traits.contains_key(&d)) {
547543
for did in dids {
548-
if self.impl_ids.entry(did).or_default().insert(impl_item.def_id()) {
549-
self.cache
550-
.impls
551-
.entry(did)
552-
.or_insert_with(Vec::new)
553-
.push(impl_item.clone());
544+
if self.impl_ids.entry(did).or_default().insert(impl_did) {
545+
self.cache.impls.entry(did).or_default().push(impl_item.clone());
554546
}
555547
}
556548
} else {
557-
let trait_did = impl_item.trait_did().expect("no trait did");
549+
let trait_did = trait_did.expect("no trait did");
558550
self.cache.orphan_trait_impls.push((trait_did, dids, impl_item));
559551
}
560552
None

src/librustdoc/json/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
217217
fn after_krate(&mut self) -> Result<(), Error> {
218218
debug!("Done with crate");
219219

220-
debug!("Adding Primitive impls");
221-
for primitive in Rc::clone(&self.cache).primitive_locations.values() {
222-
self.get_impls(*primitive);
223-
}
224-
225220
let e = ExternalCrate { crate_num: LOCAL_CRATE };
226-
227221
let index = (*self.index).clone().into_inner();
228222

229223
debug!("Constructing Output");

tests/rustdoc-json/the_smallest.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This test asserts that `index` is not polluted with unrelated items.
2+
// See https://github.com/rust-lang/rust/issues/114039
3+
4+
//@ count "$.index[*]" 1
5+
fn main() {}

0 commit comments

Comments
 (0)