about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-10-12 01:00:15 +0000
committerbors <bors@rust-lang.org>2017-10-12 01:00:15 +0000
commitfbb5054fa9fb9dac785553d6b2baa765f5c0e999 (patch)
tree4dcea4e79d7360d140187e8a1db752fdd787b746
parenta47c9f870f13603a06ffe63ab4834fc716912843 (diff)
parent23f5fbee45273879d185ab18b64ac2cd8c708fec (diff)
downloadrust-fbb5054fa9fb9dac785553d6b2baa765f5c0e999.tar.gz
rust-fbb5054fa9fb9dac785553d6b2baa765f5c0e999.zip
Auto merge of #44969 - QuietMisdreavus:impls-for-everyone, r=steveklabnik
document trait impls when the type appears in the trait's generics

Fixes #25264

![image](https://user-images.githubusercontent.com/5217170/31062309-4fc7c594-a6ef-11e7-892e-07f95bbc7976.png)
-rw-r--r--src/librustdoc/clean/mod.rs15
-rw-r--r--src/librustdoc/html/render.rs27
2 files changed, 34 insertions, 8 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 424f48a17e9..b120017dd5a 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -1681,6 +1681,21 @@ impl Type {
             _ => false
         }
     }
+
+    pub fn generics(&self) -> Option<&[Type]> {
+        match *self {
+            ResolvedPath { ref path, .. } => {
+                path.segments.last().and_then(|seg| {
+                    if let PathParameters::AngleBracketed { ref types, .. } = seg.params {
+                        Some(&**types)
+                    } else {
+                        None
+                    }
+                })
+            }
+            _ => None,
+        }
+    }
 }
 
 impl GetDefId for Type {
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index a3f446885f9..e4017244522 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -1306,7 +1306,8 @@ impl DocFolder for Cache {
                 // Figure out the id of this impl. This may map to a
                 // primitive rather than always to a struct/enum.
                 // Note: matching twice to restrict the lifetime of the `i` borrow.
-                let did = if let clean::Item { inner: clean::ImplItem(ref i), .. } = item {
+                let mut dids = vec![];
+                if let clean::Item { inner: clean::ImplItem(ref i), .. } = item {
                     let masked_trait = i.trait_.def_id().map_or(false,
                         |d| self.masked_crates.contains(&d.krate));
                     if !masked_trait {
@@ -1315,23 +1316,33 @@ impl DocFolder for Cache {
                             clean::BorrowedRef {
                                 type_: box clean::ResolvedPath { did, .. }, ..
                             } => {
-                                Some(did)
+                                dids.push(did);
                             }
                             ref t => {
-                                t.primitive_type().and_then(|t| {
+                                let did = t.primitive_type().and_then(|t| {
                                     self.primitive_locations.get(&t).cloned()
-                                })
+                                });
+
+                                if let Some(did) = did {
+                                    dids.push(did);
+                                }
+                            }
+                        }
+                    }
+
+                    if let Some(generics) = i.trait_.as_ref().and_then(|t| t.generics()) {
+                        for bound in generics {
+                            if let Some(did) = bound.def_id() {
+                                dids.push(did);
                             }
                         }
-                    } else {
-                        None
                     }
                 } else {
                     unreachable!()
                 };
-                if let Some(did) = did {
+                for did in dids {
                     self.impls.entry(did).or_insert(vec![]).push(Impl {
-                        impl_item: item,
+                        impl_item: item.clone(),
                     });
                 }
                 None