Skip to content

Commit

Permalink
rustdoc: fix duplicate blanket impls
Browse files Browse the repository at this point in the history
Fixes rust-lang#96036

This is a different approach than rust-lang#96091, an approach that should have less
performance impact.
  • Loading branch information
notriddle committed Apr 15, 2022
1 parent 327caac commit 0e853d1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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 {}

0 comments on commit 0e853d1

Please sign in to comment.