about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crates/ide/src/hover/render.rs15
-rw-r--r--crates/ide/src/hover/tests.rs30
2 files changed, 44 insertions, 1 deletions
diff --git a/crates/ide/src/hover/render.rs b/crates/ide/src/hover/render.rs
index 06762202720..1cb67c6657a 100644
--- a/crates/ide/src/hover/render.rs
+++ b/crates/ide/src/hover/render.rs
@@ -372,7 +372,20 @@ pub(super) fn definition(
         Definition::ToolModule(it) => return Some(Markup::fenced_block(&it.name(db))),
     };
 
-    markup(docs.filter(|_| config.documentation.is_some()).map(Into::into), label, mod_path)
+    let docs = match config.documentation {
+        Some(_) => docs.or_else(|| {
+            // docs are missing, for assoc items of trait impls try to fall back to the docs of the
+            // original item of the trait
+            let assoc = def.as_assoc_item(db)?;
+            let trait_ = assoc.containing_trait_impl(db)?;
+            let name = Some(assoc.name(db)?);
+            let item = trait_.items(db).into_iter().find(|it| it.name(db) == name)?;
+            item.docs(db)
+        }),
+        None => None,
+    };
+    let docs = docs.filter(|_| config.documentation.is_some()).map(Into::into);
+    markup(docs, label, mod_path)
 }
 
 fn render_builtin_attr(db: &RootDatabase, attr: hir::BuiltinAttr) -> Option<Markup> {
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index c95a0e40054..8eb16aab293 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -4888,3 +4888,33 @@ enum Enum {
         "#]],
     );
 }
+
+#[test]
+fn hover_trait_impl_assoc_item_def_doc_forwarding() {
+    check(
+        r#"
+trait T {
+    /// Trait docs
+    fn func() {}
+}
+impl T for () {
+    fn func$0() {}
+}
+"#,
+        expect![[r#"
+            *func*
+
+            ```rust
+            test
+            ```
+
+            ```rust
+            fn func()
+            ```
+
+            ---
+
+            Trait docs
+        "#]],
+    );
+}