Skip to content

Commit 376a6f9

Browse files
authored
Rollup merge of rust-lang#128385 - its-the-shrimp:fix_114039, r=aDotInTheVoid
rustdoc-json: discard non-local inherent impls for primitives Fixes rust-lang#114039 at least it should r? `@aDotInTheVoid`
2 parents 83e9b93 + 7499e21 commit 376a6f9

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
@@ -310,16 +310,16 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
310310
// `public_items` map, so we can skip inserting into the
311311
// paths map if there was already an entry present and we're
312312
// not a public item.
313-
if !self.cache.paths.contains_key(&item.item_id.expect_def_id())
313+
let item_def_id = item.item_id.expect_def_id();
314+
if !self.cache.paths.contains_key(&item_def_id)
314315
|| self
315316
.cache
316317
.effective_visibilities
317-
.is_directly_public(self.tcx, item.item_id.expect_def_id())
318+
.is_directly_public(self.tcx, item_def_id)
318319
{
319-
self.cache.paths.insert(
320-
item.item_id.expect_def_id(),
321-
(self.cache.stack.clone(), item.type_()),
322-
);
320+
self.cache
321+
.paths
322+
.insert(item_def_id, (self.cache.stack.clone(), item.type_()));
323323
}
324324
}
325325
}
@@ -381,9 +381,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
381381
&& adt.is_fundamental()
382382
{
383383
for ty in generics {
384-
if let Some(did) = ty.def_id(self.cache) {
385-
dids.insert(did);
386-
}
384+
dids.extend(ty.def_id(self.cache));
387385
}
388386
}
389387
}
@@ -396,32 +394,26 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
396394
.primitive_type()
397395
.and_then(|t| self.cache.primitive_locations.get(&t).cloned());
398396

399-
if let Some(did) = did {
400-
dids.insert(did);
401-
}
397+
dids.extend(did);
402398
}
403399
}
404400

405401
if let Some(generics) = i.trait_.as_ref().and_then(|t| t.generics()) {
406402
for bound in generics {
407-
if let Some(did) = bound.def_id(self.cache) {
408-
dids.insert(did);
409-
}
403+
dids.extend(bound.def_id(self.cache));
410404
}
411405
}
412406
let impl_item = Impl { impl_item: item };
413-
if impl_item.trait_did().map_or(true, |d| self.cache.traits.contains_key(&d)) {
407+
let impl_did = impl_item.def_id();
408+
let trait_did = impl_item.trait_did();
409+
if trait_did.map_or(true, |d| self.cache.traits.contains_key(&d)) {
414410
for did in dids {
415-
if self.impl_ids.entry(did).or_default().insert(impl_item.def_id()) {
416-
self.cache
417-
.impls
418-
.entry(did)
419-
.or_insert_with(Vec::new)
420-
.push(impl_item.clone());
411+
if self.impl_ids.entry(did).or_default().insert(impl_did) {
412+
self.cache.impls.entry(did).or_default().push(impl_item.clone());
421413
}
422414
}
423415
} else {
424-
let trait_did = impl_item.trait_did().expect("no trait did");
416+
let trait_did = trait_did.expect("no trait did");
425417
self.cache.orphan_trait_impls.push((trait_did, dids, impl_item));
426418
}
427419
None

src/librustdoc/json/mod.rs

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

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

228222
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)