about summary refs log tree commit diff
path: root/src/librustdoc/html/render.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-01-04 17:11:02 +0000
committerbors <bors@rust-lang.org>2017-01-04 17:11:02 +0000
commit05f4a75ebaccdf3646fbea4b560a3a0dfc1be9e2 (patch)
tree70ea913aaea837bf24a663b4c47e59f34287cc8e /src/librustdoc/html/render.rs
parentd40d01bd0e7d9d20bb3454a3d0870f00b805a01c (diff)
parent346a44211087a36de91877545ea28e9af501db6c (diff)
downloadrust-05f4a75ebaccdf3646fbea4b560a3a0dfc1be9e2.tar.gz
rust-05f4a75ebaccdf3646fbea4b560a3a0dfc1be9e2.zip
Auto merge of #38414 - estebank:doc-dissambiguate, r=steveklabnik
Rustdoc: disambiguate Implementors when the type name is not unique

Presentation [goes from](https://doc.rust-lang.org/stable/std/iter/trait.ExactSizeIterator.html#implementors):

<img width="492" alt="" src="https://cloud.githubusercontent.com/assets/1606434/21276752/b2b50474-c387-11e6-96e1-9766851da269.png">

to:

<img width="787" alt="" src="https://cloud.githubusercontent.com/assets/1606434/21276763/bb37f6b0-c387-11e6-8596-9163cb254674.png">

on cases where there're multiple implementors with the same name.

Fixes #37762.
Diffstat (limited to 'src/librustdoc/html/render.rs')
-rw-r--r--src/librustdoc/html/render.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index ff7133f5d0c..9ea4bc436bf 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -2122,9 +2122,25 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
         <ul class='item-list' id='implementors-list'>
     ")?;
     if let Some(implementors) = cache.implementors.get(&it.def_id) {
-        for i in implementors {
+        let mut implementor_count: FxHashMap<&str, usize> = FxHashMap();
+        for implementor in implementors {
+            if let clean::Type::ResolvedPath {ref path, ..} = implementor.impl_.for_ {
+                *implementor_count.entry(path.last_name()).or_insert(0) += 1;
+            }
+        }
+
+        for implementor in implementors {
             write!(w, "<li><code>")?;
-            fmt_impl_for_trait_page(&i.impl_, w)?;
+            // If there's already another implementor that has the same abbridged name, use the
+            // full path, for example in `std::iter::ExactSizeIterator`
+            let use_absolute = if let clean::Type::ResolvedPath {
+                ref path, ..
+            } = implementor.impl_.for_ {
+                implementor_count[path.last_name()] > 1
+            } else {
+                false
+            };
+            fmt_impl_for_trait_page(&implementor.impl_, w, use_absolute)?;
             writeln!(w, "</code></li>")?;
         }
     }