Skip to content

Commit 3e7f501

Browse files
committed
Auto merge of #45620 - ollie27:rustdoc_impl_generic_dupe, r=QuietMisdreavus
rustdoc: Fix duplicated impls with generics The same type can appear multiple times in impls so we need to use a set to avoid adding it multiple times. Fixes: #45584
2 parents a17e724 + 676b4bb commit 3e7f501

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

Diff for: src/librustdoc/html/render.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ impl DocFolder for Cache {
13261326
// Figure out the id of this impl. This may map to a
13271327
// primitive rather than always to a struct/enum.
13281328
// Note: matching twice to restrict the lifetime of the `i` borrow.
1329-
let mut dids = vec![];
1329+
let mut dids = FxHashSet();
13301330
if let clean::Item { inner: clean::ImplItem(ref i), .. } = item {
13311331
let masked_trait = i.trait_.def_id().map_or(false,
13321332
|d| self.masked_crates.contains(&d.krate));
@@ -1336,15 +1336,15 @@ impl DocFolder for Cache {
13361336
clean::BorrowedRef {
13371337
type_: box clean::ResolvedPath { did, .. }, ..
13381338
} => {
1339-
dids.push(did);
1339+
dids.insert(did);
13401340
}
13411341
ref t => {
13421342
let did = t.primitive_type().and_then(|t| {
13431343
self.primitive_locations.get(&t).cloned()
13441344
});
13451345

13461346
if let Some(did) = did {
1347-
dids.push(did);
1347+
dids.insert(did);
13481348
}
13491349
}
13501350
}
@@ -1353,7 +1353,7 @@ impl DocFolder for Cache {
13531353
if let Some(generics) = i.trait_.as_ref().and_then(|t| t.generics()) {
13541354
for bound in generics {
13551355
if let Some(did) = bound.def_id() {
1356-
dids.push(did);
1356+
dids.insert(did);
13571357
}
13581358
}
13591359
}

Diff for: src/test/rustdoc/issue-45584.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_name = "foo"]
12+
13+
pub trait Bar<T, U> {}
14+
15+
// @has 'foo/struct.Foo1.html'
16+
pub struct Foo1;
17+
// @count - '//*[@class="impl"]' 1
18+
// @has - '//*[@class="impl"]' "impl Bar<Foo1, &'static Foo1> for Foo1"
19+
impl Bar<Foo1, &'static Foo1> for Foo1 {}
20+
21+
// @has 'foo/struct.Foo2.html'
22+
pub struct Foo2;
23+
// @count - '//*[@class="impl"]' 1
24+
// @has - '//*[@class="impl"]' "impl Bar<&'static Foo2, Foo2> for u8"
25+
impl Bar<&'static Foo2, Foo2> for u8 {}

0 commit comments

Comments
 (0)