Skip to content

Commit 0e853d1

Browse files
committed
rustdoc: fix duplicate blanket impls
Fixes rust-lang#96036 This is a different approach than rust-lang#96091, an approach that should have less performance impact.
1 parent 327caac commit 0e853d1

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/librustdoc/formats/cache.rs

+10
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,20 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
464464
let impl_item = Impl { impl_item: item };
465465
if impl_item.trait_did().map_or(true, |d| self.cache.traits.contains_key(&d)) {
466466
for did in dids {
467+
if let ItemId::Blanket { for_, .. } = &impl_item.impl_item.def_id
468+
&& for_ != &did {
469+
continue;
470+
}
467471
self.cache.impls.entry(did).or_insert_with(Vec::new).push(impl_item.clone());
468472
}
469473
} else {
470474
let trait_did = impl_item.trait_did().expect("no trait did");
475+
if let ItemId::Blanket { for_, .. } = &impl_item.impl_item.def_id {
476+
dids = dids
477+
.into_iter()
478+
.filter(|did| did == for_)
479+
.collect();
480+
}
471481
self.cache.orphan_trait_impls.push((trait_did, dids, impl_item));
472482
}
473483
None

src/test/rustdoc/duplicated_impl.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// This test ensures that the same implementation doesn't show more than once.
2+
// It's a regression test for https://github.com./rust-lang/rust/issues/96036.
3+
4+
#![crate_name = "foo"]
5+
6+
// We check that there is only one "impl<T> Something<Whatever> for T" listed in the
7+
// blanket implementations.
8+
9+
// @has 'foo/struct.Whatever.html'
10+
// @count - '//*[@id="blanket-implementations-list"]/section[@class="impl has-srclink"]' 1
11+
12+
pub trait Something<T> { }
13+
pub struct Whatever;
14+
impl<T> Something<Whatever> for T {}

0 commit comments

Comments
 (0)