diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2017-08-18 00:08:12 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2017-08-24 11:38:58 +0200 |
| commit | b4a32434c0cb859315a4395d003c625f87080e8f (patch) | |
| tree | ca236cab2a06d176fa4d42805a8bc7bdf035447f | |
| parent | dd39ecf368a3cdb937e129f36a2a342d0c9358f0 (diff) | |
| download | rust-b4a32434c0cb859315a4395d003c625f87080e8f.tar.gz rust-b4a32434c0cb859315a4395d003c625f87080e8f.zip | |
Remove duplicates in rustdoc
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/html/render.rs | 31 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index f4aef8ab377..1df0ac337a7 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -323,6 +323,10 @@ impl Item { pub fn is_union(&self) -> bool { self.type_() == ItemType::Union } + pub fn is_import(&self) -> bool { + self.type_() == ItemType::Import + } + pub fn is_stripped(&self) -> bool { match self.inner { StrippedItem(..) => true, _ => false } } diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 6593d6dfd6c..e113165b9ab 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1764,6 +1764,37 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, } indices.sort_by(|&i1, &i2| cmp(&items[i1], &items[i2], i1, i2)); + // This call is to remove reexport duplicates in cases such as: + // + // ``` + // pub mod foo { + // pub mod bar { + // pub trait Double { fn foo(); } + // } + // } + // + // pub use foo::bar::*; + // pub use foo::*; + // ``` + // + // `Double` will appear twice in the generated docs. + // + // FIXME: This code is quite ugly and could be improved. Small issue: DefId + // can be identical even if the elements are different (mostly in imports). + // So in case this is an import, we keep everything by adding a "unique id" + // (which is the position in the vector). + indices.dedup_by_key(|i| (items[*i].def_id, + if items[*i].name.as_ref().is_some() { + Some(full_path(cx, &items[*i]).clone()) + } else { + None + }, + items[*i].type_(), + if items[*i].is_import() { + *i + } else { + 0 + })); debug!("{:?}", indices); let mut curty = None; |
