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: fix duplicate blanket impls #96095

Closed
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
10 changes: 10 additions & 0 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,20 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
let impl_item = Impl { impl_item: item };
if impl_item.trait_did().map_or(true, |d| self.cache.traits.contains_key(&d)) {
for did in dids {
if let ItemId::Blanket { for_, .. } = &impl_item.impl_item.def_id
&& for_ != &did {
continue;
}
self.cache.impls.entry(did).or_insert_with(Vec::new).push(impl_item.clone());
}
} else {
let trait_did = impl_item.trait_did().expect("no trait did");
if let ItemId::Blanket { for_, .. } = &impl_item.impl_item.def_id {
dids = dids
.into_iter()
.filter(|did| did == for_)
.collect();
}
self.cache.orphan_trait_impls.push((trait_did, dids, impl_item));
}
None
Expand Down
14 changes: 14 additions & 0 deletions src/test/rustdoc/duplicated_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// This test ensures that the same implementation doesn't show more than once.
// It's a regression test for https://github.com/rust-lang/rust/issues/96036.

#![crate_name = "foo"]

// We check that there is only one "impl<T> Something<Whatever> for T" listed in the
// blanket implementations.

// @has 'foo/struct.Whatever.html'
// @count - '//*[@id="blanket-implementations-list"]/section[@class="impl has-srclink"]' 1

pub trait Something<T> { }
pub struct Whatever;
impl<T> Something<Whatever> for T {}