This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed
Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -372,7 +372,20 @@ pub(super) fn definition(
372372 Definition :: ToolModule ( it) => return Some ( Markup :: fenced_block ( & it. name ( db) ) ) ,
373373 } ;
374374
375- markup ( docs. filter ( |_| config. documentation . is_some ( ) ) . map ( Into :: into) , label, mod_path)
375+ let docs = match config. documentation {
376+ Some ( _) => docs. or_else ( || {
377+ // docs are missing, for assoc items of trait impls try to fall back to the docs of the
378+ // original item of the trait
379+ let assoc = def. as_assoc_item ( db) ?;
380+ let trait_ = assoc. containing_trait_impl ( db) ?;
381+ let name = Some ( assoc. name ( db) ?) ;
382+ let item = trait_. items ( db) . into_iter ( ) . find ( |it| it. name ( db) == name) ?;
383+ item. docs ( db)
384+ } ) ,
385+ None => None ,
386+ } ;
387+ let docs = docs. filter ( |_| config. documentation . is_some ( ) ) . map ( Into :: into) ;
388+ markup ( docs, label, mod_path)
376389}
377390
378391fn render_builtin_attr ( db : & RootDatabase , attr : hir:: BuiltinAttr ) -> Option < Markup > {
Original file line number Diff line number Diff line change @@ -4888,3 +4888,33 @@ enum Enum {
48884888 "# ] ] ,
48894889 ) ;
48904890}
4891+
4892+ #[ test]
4893+ fn hover_trait_impl_assoc_item_def_doc_forwarding ( ) {
4894+ check (
4895+ r#"
4896+ trait T {
4897+ /// Trait docs
4898+ fn func() {}
4899+ }
4900+ impl T for () {
4901+ fn func$0() {}
4902+ }
4903+ "# ,
4904+ expect ! [ [ r#"
4905+ *func*
4906+
4907+ ```rust
4908+ test
4909+ ```
4910+
4911+ ```rust
4912+ fn func()
4913+ ```
4914+
4915+ ---
4916+
4917+ Trait docs
4918+ "# ] ] ,
4919+ ) ;
4920+ }
You can’t perform that action at this time.
0 commit comments