Skip to content

Commit 676b4bb

Browse files
committed
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.
1 parent 7da9a5e commit 676b4bb

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/librustdoc/html/render.rs

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

13451345
if let Some(did) = did {
1346-
dids.push(did);
1346+
dids.insert(did);
13471347
}
13481348
}
13491349
}
@@ -1352,7 +1352,7 @@ impl DocFolder for Cache {
13521352
if let Some(generics) = i.trait_.as_ref().and_then(|t| t.generics()) {
13531353
for bound in generics {
13541354
if let Some(did) = bound.def_id() {
1355-
dids.push(did);
1355+
dids.insert(did);
13561356
}
13571357
}
13581358
}

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)