Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc-json: discard non-local inherent impls for primitives #128385

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 15 additions & 23 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,16 +442,16 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
// `public_items` map, so we can skip inserting into the
// paths map if there was already an entry present and we're
// not a public item.
if !self.cache.paths.contains_key(&item.item_id.expect_def_id())
let item_def_id = item.item_id.expect_def_id();
if !self.cache.paths.contains_key(&item_def_id)
|| self
.cache
.effective_visibilities
.is_directly_public(self.tcx, item.item_id.expect_def_id())
.is_directly_public(self.tcx, item_def_id)
{
self.cache.paths.insert(
item.item_id.expect_def_id(),
(self.cache.stack.clone(), item.type_()),
);
self.cache
.paths
.insert(item_def_id, (self.cache.stack.clone(), item.type_()));
}
}
}
Expand Down Expand Up @@ -514,9 +514,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
&& adt.is_fundamental()
{
for ty in generics {
if let Some(did) = ty.def_id(self.cache) {
dids.insert(did);
}
dids.extend(ty.def_id(self.cache));
}
}
}
Expand All @@ -529,32 +527,26 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
.primitive_type()
.and_then(|t| self.cache.primitive_locations.get(&t).cloned());

if let Some(did) = did {
dids.insert(did);
}
dids.extend(did);
}
}

if let Some(generics) = i.trait_.as_ref().and_then(|t| t.generics()) {
for bound in generics {
if let Some(did) = bound.def_id(self.cache) {
dids.insert(did);
}
dids.extend(bound.def_id(self.cache));
}
}
let impl_item = Impl { impl_item: item };
if impl_item.trait_did().map_or(true, |d| self.cache.traits.contains_key(&d)) {
let impl_did = impl_item.def_id();
let trait_did = impl_item.trait_did();
if trait_did.map_or(true, |d| self.cache.traits.contains_key(&d)) {
for did in dids {
if self.impl_ids.entry(did).or_default().insert(impl_item.def_id()) {
self.cache
.impls
.entry(did)
.or_insert_with(Vec::new)
.push(impl_item.clone());
if self.impl_ids.entry(did).or_default().insert(impl_did) {
self.cache.impls.entry(did).or_default().push(impl_item.clone());
}
}
} else {
let trait_did = impl_item.trait_did().expect("no trait did");
let trait_did = trait_did.expect("no trait did");
self.cache.orphan_trait_impls.push((trait_did, dids, impl_item));
}
None
Expand Down
6 changes: 0 additions & 6 deletions src/librustdoc/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
fn after_krate(&mut self) -> Result<(), Error> {
debug!("Done with crate");

debug!("Adding Primitive impls");
for primitive in Rc::clone(&self.cache).primitive_locations.values() {
self.get_impls(*primitive);
}

let e = ExternalCrate { crate_num: LOCAL_CRATE };

let index = (*self.index).clone().into_inner();

debug!("Constructing Output");
Expand Down
5 changes: 5 additions & 0 deletions tests/rustdoc-json/the_smallest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This test asserts that `index` is not polluted with unrelated items.
// See https://github.com/rust-lang/rust/issues/114039

//@ count "$.index[*]" 1
fn main() {}
Loading