Skip to content

Commit b4a3243

Browse files
Remove duplicates in rustdoc
1 parent dd39ecf commit b4a3243

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/librustdoc/clean/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ impl Item {
323323
pub fn is_union(&self) -> bool {
324324
self.type_() == ItemType::Union
325325
}
326+
pub fn is_import(&self) -> bool {
327+
self.type_() == ItemType::Import
328+
}
329+
326330
pub fn is_stripped(&self) -> bool {
327331
match self.inner { StrippedItem(..) => true, _ => false }
328332
}

src/librustdoc/html/render.rs

+31
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,37 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
17641764
}
17651765

17661766
indices.sort_by(|&i1, &i2| cmp(&items[i1], &items[i2], i1, i2));
1767+
// This call is to remove reexport duplicates in cases such as:
1768+
//
1769+
// ```
1770+
// pub mod foo {
1771+
// pub mod bar {
1772+
// pub trait Double { fn foo(); }
1773+
// }
1774+
// }
1775+
//
1776+
// pub use foo::bar::*;
1777+
// pub use foo::*;
1778+
// ```
1779+
//
1780+
// `Double` will appear twice in the generated docs.
1781+
//
1782+
// FIXME: This code is quite ugly and could be improved. Small issue: DefId
1783+
// can be identical even if the elements are different (mostly in imports).
1784+
// So in case this is an import, we keep everything by adding a "unique id"
1785+
// (which is the position in the vector).
1786+
indices.dedup_by_key(|i| (items[*i].def_id,
1787+
if items[*i].name.as_ref().is_some() {
1788+
Some(full_path(cx, &items[*i]).clone())
1789+
} else {
1790+
None
1791+
},
1792+
items[*i].type_(),
1793+
if items[*i].is_import() {
1794+
*i
1795+
} else {
1796+
0
1797+
}));
17671798

17681799
debug!("{:?}", indices);
17691800
let mut curty = None;

0 commit comments

Comments
 (0)