@@ -273,7 +273,7 @@ pub(super) fn keyword(
273273 let markup = process_markup (
274274 sema. db ,
275275 Definition :: Module ( doc_owner) ,
276- & markup ( Some ( docs. into ( ) ) , description, None ) ,
276+ & markup ( Some ( docs. into ( ) ) , description, None , None ) ,
277277 config,
278278 ) ;
279279 Some ( HoverResult { markup, actions } )
@@ -539,28 +539,29 @@ pub(super) fn definition(
539539 _ => None ,
540540 } ;
541541
542- let mut desc = String :: new ( ) ;
543- if let Some ( notable_traits) = render_notable_trait_comment ( db, notable_traits, edition) {
544- desc. push_str ( & notable_traits) ;
545- desc. push ( '\n' ) ;
546- }
542+ let mut extra = String :: new ( ) ;
547543 if hovered_definition {
544+ if let Some ( notable_traits) = render_notable_trait ( db, notable_traits, edition) {
545+ extra. push_str ( "\n ___\n " ) ;
546+ extra. push_str ( & notable_traits) ;
547+ }
548548 if let Some ( layout_info) = layout_info ( ) {
549- desc . push_str ( & layout_info ) ;
550- desc . push ( '\n' ) ;
549+ extra . push_str ( " \n ___ \n " ) ;
550+ extra . push_str ( & layout_info ) ;
551551 }
552552 if let Some ( dyn_compatibility_info) = dyn_compatibility_info ( ) {
553- desc . push_str ( & dyn_compatibility_info ) ;
554- desc . push ( '\n' ) ;
553+ extra . push_str ( " \n ___ \n " ) ;
554+ extra . push_str ( & dyn_compatibility_info ) ;
555555 }
556556 }
557+ let mut desc = String :: new ( ) ;
557558 desc. push_str ( & label) ;
558559 if let Some ( value) = value ( ) {
559560 desc. push_str ( " = " ) ;
560561 desc. push_str ( & value) ;
561562 }
562563
563- markup ( docs. map ( Into :: into) , desc, mod_path)
564+ markup ( docs. map ( Into :: into) , desc, extra . is_empty ( ) . not ( ) . then_some ( extra ) , mod_path)
564565}
565566
566567pub ( super ) fn literal (
@@ -630,7 +631,7 @@ pub(super) fn literal(
630631 Some ( s. into ( ) )
631632}
632633
633- fn render_notable_trait_comment (
634+ fn render_notable_trait (
634635 db : & RootDatabase ,
635636 notable_traits : & [ ( Trait , Vec < ( Option < Type > , Name ) > ) ] ,
636637 edition : Edition ,
@@ -639,7 +640,7 @@ fn render_notable_trait_comment(
639640 let mut needs_impl_header = true ;
640641 for ( trait_, assoc_types) in notable_traits {
641642 desc. push_str ( if mem:: take ( & mut needs_impl_header) {
642- "// Implements notable traits: "
643+ "Implements notable traits: "
643644 } else {
644645 ", "
645646 } ) ;
@@ -732,13 +733,12 @@ fn type_info(
732733 )
733734 . into ( )
734735 } else {
735- let mut desc =
736- match render_notable_trait_comment ( db, & notable_traits ( db, & original) , edition) {
737- Some ( desc) => desc + "\n " ,
738- None => String :: new ( ) ,
739- } ;
740- format_to ! ( desc, "{}" , original. display( db, edition) ) ;
741- Markup :: fenced_block ( & desc)
736+ let mut desc = format ! ( "```rust\n {}\n ```" , original. display( db, edition) ) ;
737+ if let Some ( extra) = render_notable_trait ( db, & notable_traits ( db, & original) , edition) {
738+ desc. push_str ( "\n ___\n " ) ;
739+ desc. push_str ( & extra) ;
740+ } ;
741+ desc. into ( )
742742 } ;
743743 if let Some ( actions) = HoverAction :: goto_type_from_targets ( db, targets, edition) {
744744 res. actions . push ( actions) ;
@@ -790,20 +790,16 @@ fn closure_ty(
790790 } ;
791791 let mut markup = format ! ( "```rust\n {}" , c. display_with_id( sema. db, edition) ) ;
792792
793+ if let Some ( trait_) = c. fn_trait ( sema. db ) . get_id ( sema. db , original. krate ( sema. db ) . into ( ) ) {
794+ push_new_def ( hir:: Trait :: from ( trait_) . into ( ) )
795+ }
796+ format_to ! ( markup, "\n {}\n ```" , c. display_with_impl( sema. db, edition) , ) ;
793797 if let Some ( layout) =
794798 render_memory_layout ( config. memory_layout , || original. layout ( sema. db ) , |_| None , |_| None )
795799 {
796- format_to ! ( markup, " {layout}" ) ;
797- }
798- if let Some ( trait_) = c. fn_trait ( sema. db ) . get_id ( sema. db , original. krate ( sema. db ) . into ( ) ) {
799- push_new_def ( hir:: Trait :: from ( trait_) . into ( ) )
800+ format_to ! ( markup, "\n ___\n {layout}" ) ;
800801 }
801- format_to ! (
802- markup,
803- "\n {}\n ```{adjusted}\n \n ## Captures\n {}" ,
804- c. display_with_impl( sema. db, edition) ,
805- captures_rendered,
806- ) ;
802+ format_to ! ( markup, "{adjusted}\n \n ## Captures\n {}" , captures_rendered, ) ;
807803
808804 let mut res = HoverResult :: default ( ) ;
809805 if let Some ( actions) = HoverAction :: goto_type_from_targets ( sema. db , targets, edition) {
@@ -828,15 +824,24 @@ fn definition_mod_path(db: &RootDatabase, def: &Definition, edition: Edition) ->
828824 . map ( |module| path ( db, module, definition_owner_name ( db, def, edition) , edition) )
829825}
830826
831- fn markup ( docs : Option < String > , desc : String , mod_path : Option < String > ) -> Markup {
827+ fn markup (
828+ docs : Option < String > ,
829+ rust : String ,
830+ extra : Option < String > ,
831+ mod_path : Option < String > ,
832+ ) -> Markup {
832833 let mut buf = String :: new ( ) ;
833834
834835 if let Some ( mod_path) = mod_path {
835836 if !mod_path. is_empty ( ) {
836837 format_to ! ( buf, "```rust\n {}\n ```\n \n " , mod_path) ;
837838 }
838839 }
839- format_to ! ( buf, "```rust\n {}\n ```" , desc) ;
840+ format_to ! ( buf, "```rust\n {}\n ```" , rust) ;
841+
842+ if let Some ( extra) = extra {
843+ buf. push_str ( & extra) ;
844+ }
840845
841846 if let Some ( doc) = docs {
842847 format_to ! ( buf, "\n ___\n \n {}" , doc) ;
@@ -866,7 +871,7 @@ fn render_memory_layout(
866871 let config = config?;
867872 let layout = layout ( ) . ok ( ) ?;
868873
869- let mut label = String :: from ( "// " ) ;
874+ let mut label = String :: new ( ) ;
870875
871876 if let Some ( render) = config. size {
872877 let size = match tag ( & layout) {
@@ -998,10 +1003,10 @@ fn render_dyn_compatibility(
9981003 safety : Option < DynCompatibilityViolation > ,
9991004) {
10001005 let Some ( osv) = safety else {
1001- buf. push_str ( "// Is Dyn compatible" ) ;
1006+ buf. push_str ( "Is Dyn compatible" ) ;
10021007 return ;
10031008 } ;
1004- buf. push_str ( "// Is not Dyn compatible due to " ) ;
1009+ buf. push_str ( "Is not Dyn compatible due to " ) ;
10051010 match osv {
10061011 DynCompatibilityViolation :: SizedSelf => {
10071012 buf. push_str ( "having a `Self: Sized` bound" ) ;
0 commit comments