diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index 53159709586c6..924e9761a1f04 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -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 diff --git a/src/test/rustdoc/duplicated_impl.rs b/src/test/rustdoc/duplicated_impl.rs new file mode 100644 index 0000000000000..4e901b31c9076 --- /dev/null +++ b/src/test/rustdoc/duplicated_impl.rs @@ -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 Something 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 { } +pub struct Whatever; +impl Something for T {}