@@ -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 } )
@@ -419,6 +419,7 @@ pub(super) fn definition(
419419 famous_defs : Option < & FamousDefs < ' _ , ' _ > > ,
420420 notable_traits : & [ ( Trait , Vec < ( Option < Type > , Name ) > ) ] ,
421421 macro_arm : Option < u32 > ,
422+ hovered_definition : bool ,
422423 config : & HoverConfig ,
423424 edition : Edition ,
424425) -> Markup {
@@ -456,7 +457,7 @@ pub(super) fn definition(
456457 _ => def. label ( db, edition) ,
457458 } ;
458459 let docs = def. docs ( db, famous_defs, edition) ;
459- let value = ( || match def {
460+ let value = || match def {
460461 Definition :: Variant ( it) => {
461462 if !it. parent_enum ( db) . is_data_carrying ( db) {
462463 match it. eval ( db) {
@@ -494,9 +495,9 @@ pub(super) fn definition(
494495 Some ( body. to_string ( ) )
495496 }
496497 _ => None ,
497- } ) ( ) ;
498+ } ;
498499
499- let layout_info = match def {
500+ let layout_info = || match def {
500501 Definition :: Field ( it) => render_memory_layout (
501502 config. memory_layout ,
502503 || it. layout ( db) ,
@@ -529,34 +530,38 @@ pub(super) fn definition(
529530 _ => None ,
530531 } ;
531532
532- let dyn_compatibility_info = if let Definition :: Trait ( it) = def {
533- let mut dyn_compatibility_info = String :: new ( ) ;
534- render_dyn_compatibility ( db, & mut dyn_compatibility_info, it. dyn_compatibility ( db) ) ;
535- Some ( dyn_compatibility_info)
536- } else {
537- None
533+ let dyn_compatibility_info = || match def {
534+ Definition :: Trait ( it) => {
535+ let mut dyn_compatibility_info = String :: new ( ) ;
536+ render_dyn_compatibility ( db, & mut dyn_compatibility_info, it. dyn_compatibility ( db) ) ;
537+ Some ( dyn_compatibility_info)
538+ }
539+ _ => None ,
538540 } ;
539541
540- let mut desc = String :: new ( ) ;
541- if let Some ( notable_traits) = render_notable_trait_comment ( db, notable_traits, edition) {
542- desc. push_str ( & notable_traits) ;
543- desc. push ( '\n' ) ;
544- }
545- if let Some ( layout_info) = layout_info {
546- desc. push_str ( & layout_info) ;
547- desc. push ( '\n' ) ;
548- }
549- if let Some ( dyn_compatibility_info) = dyn_compatibility_info {
550- desc. push_str ( & dyn_compatibility_info) ;
551- desc. push ( '\n' ) ;
542+ let mut extra = String :: new ( ) ;
543+ 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+ }
548+ if let Some ( layout_info) = layout_info ( ) {
549+ extra. push_str ( "\n ___\n " ) ;
550+ extra. push_str ( & layout_info) ;
551+ }
552+ if let Some ( dyn_compatibility_info) = dyn_compatibility_info ( ) {
553+ extra. push_str ( "\n ___\n " ) ;
554+ extra. push_str ( & dyn_compatibility_info) ;
555+ }
552556 }
557+ let mut desc = String :: new ( ) ;
553558 desc. push_str ( & label) ;
554- if let Some ( value) = value {
559+ if let Some ( value) = value ( ) {
555560 desc. push_str ( " = " ) ;
556561 desc. push_str ( & value) ;
557562 }
558563
559- markup ( docs. map ( Into :: into) , desc, mod_path)
564+ markup ( docs. map ( Into :: into) , desc, extra . is_empty ( ) . not ( ) . then_some ( extra ) , mod_path)
560565}
561566
562567pub ( super ) fn literal (
@@ -626,7 +631,7 @@ pub(super) fn literal(
626631 Some ( s. into ( ) )
627632}
628633
629- fn render_notable_trait_comment (
634+ fn render_notable_trait (
630635 db : & RootDatabase ,
631636 notable_traits : & [ ( Trait , Vec < ( Option < Type > , Name ) > ) ] ,
632637 edition : Edition ,
@@ -635,7 +640,7 @@ fn render_notable_trait_comment(
635640 let mut needs_impl_header = true ;
636641 for ( trait_, assoc_types) in notable_traits {
637642 desc. push_str ( if mem:: take ( & mut needs_impl_header) {
638- "// Implements notable traits: "
643+ "Implements notable traits: "
639644 } else {
640645 ", "
641646 } ) ;
@@ -728,13 +733,12 @@ fn type_info(
728733 )
729734 . into ( )
730735 } else {
731- let mut desc =
732- match render_notable_trait_comment ( db, & notable_traits ( db, & original) , edition) {
733- Some ( desc) => desc + "\n " ,
734- None => String :: new ( ) ,
735- } ;
736- format_to ! ( desc, "{}" , original. display( db, edition) ) ;
737- 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 ( )
738742 } ;
739743 if let Some ( actions) = HoverAction :: goto_type_from_targets ( db, targets, edition) {
740744 res. actions . push ( actions) ;
@@ -786,20 +790,16 @@ fn closure_ty(
786790 } ;
787791 let mut markup = format ! ( "```rust\n {}" , c. display_with_id( sema. db, edition) ) ;
788792
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) , ) ;
789797 if let Some ( layout) =
790798 render_memory_layout ( config. memory_layout , || original. layout ( sema. db ) , |_| None , |_| None )
791799 {
792- format_to ! ( markup, " {layout}" ) ;
800+ format_to ! ( markup, "\n ___ \n {layout}" ) ;
793801 }
794- if let Some ( trait_) = c. fn_trait ( sema. db ) . get_id ( sema. db , original. krate ( sema. db ) . into ( ) ) {
795- push_new_def ( hir:: Trait :: from ( trait_) . into ( ) )
796- }
797- format_to ! (
798- markup,
799- "\n {}\n ```{adjusted}\n \n ## Captures\n {}" ,
800- c. display_with_impl( sema. db, edition) ,
801- captures_rendered,
802- ) ;
802+ format_to ! ( markup, "{adjusted}\n \n ## Captures\n {}" , captures_rendered, ) ;
803803
804804 let mut res = HoverResult :: default ( ) ;
805805 if let Some ( actions) = HoverAction :: goto_type_from_targets ( sema. db , targets, edition) {
@@ -824,15 +824,24 @@ fn definition_mod_path(db: &RootDatabase, def: &Definition, edition: Edition) ->
824824 . map ( |module| path ( db, module, definition_owner_name ( db, def, edition) , edition) )
825825}
826826
827- 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 {
828833 let mut buf = String :: new ( ) ;
829834
830835 if let Some ( mod_path) = mod_path {
831836 if !mod_path. is_empty ( ) {
832837 format_to ! ( buf, "```rust\n {}\n ```\n \n " , mod_path) ;
833838 }
834839 }
835- 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+ }
836845
837846 if let Some ( doc) = docs {
838847 format_to ! ( buf, "\n ___\n \n {}" , doc) ;
@@ -862,7 +871,7 @@ fn render_memory_layout(
862871 let config = config?;
863872 let layout = layout ( ) . ok ( ) ?;
864873
865- let mut label = String :: from ( "// " ) ;
874+ let mut label = String :: new ( ) ;
866875
867876 if let Some ( render) = config. size {
868877 let size = match tag ( & layout) {
@@ -994,55 +1003,53 @@ fn render_dyn_compatibility(
9941003 safety : Option < DynCompatibilityViolation > ,
9951004) {
9961005 let Some ( osv) = safety else {
997- buf. push_str ( "// Dyn Compatible: Yes " ) ;
1006+ buf. push_str ( "Is Dyn compatible " ) ;
9981007 return ;
9991008 } ;
1000- buf. push_str ( "// Dyn Compatible: No \n // - Reason: " ) ;
1009+ buf. push_str ( "Is not Dyn compatible due to " ) ;
10011010 match osv {
10021011 DynCompatibilityViolation :: SizedSelf => {
1003- buf. push_str ( "has a `Self: Sized` bound" ) ;
1012+ buf. push_str ( "having a `Self: Sized` bound" ) ;
10041013 }
10051014 DynCompatibilityViolation :: SelfReferential => {
1006- buf. push_str ( "has a bound that references `Self`" ) ;
1015+ buf. push_str ( "having a bound that references `Self`" ) ;
10071016 }
10081017 DynCompatibilityViolation :: Method ( func, mvc) => {
10091018 let name = hir:: Function :: from ( func) . name ( db) ;
1010- format_to ! (
1011- buf,
1012- "has a method `{}` that is non dispatchable because of:\n // - " ,
1013- name. as_str( )
1014- ) ;
1019+ format_to ! ( buf, "having a method `{}` that is not dispatchable due to " , name. as_str( ) ) ;
10151020 let desc = match mvc {
10161021 MethodViolationCode :: StaticMethod => "missing a receiver" ,
1017- MethodViolationCode :: ReferencesSelfInput => "a parameter references `Self`" ,
1018- MethodViolationCode :: ReferencesSelfOutput => "the return type references `Self`" ,
1022+ MethodViolationCode :: ReferencesSelfInput => "having a parameter referencing `Self`" ,
1023+ MethodViolationCode :: ReferencesSelfOutput => "the return type referencing `Self`" ,
10191024 MethodViolationCode :: ReferencesImplTraitInTrait => {
1020- "the return type contains `impl Trait`"
1025+ "the return type containing `impl Trait`"
10211026 }
10221027 MethodViolationCode :: AsyncFn => "being async" ,
10231028 MethodViolationCode :: WhereClauseReferencesSelf => {
1024- "a where clause references `Self`"
1029+ "a where clause referencing `Self`"
1030+ }
1031+ MethodViolationCode :: Generic => "having a const or type generic parameter" ,
1032+ MethodViolationCode :: UndispatchableReceiver => {
1033+ "having a non-dispatchable receiver type"
10251034 }
1026- MethodViolationCode :: Generic => "a non-lifetime generic parameter" ,
1027- MethodViolationCode :: UndispatchableReceiver => "a non-dispatchable receiver type" ,
10281035 } ;
10291036 buf. push_str ( desc) ;
10301037 }
10311038 DynCompatibilityViolation :: AssocConst ( const_) => {
10321039 let name = hir:: Const :: from ( const_) . name ( db) ;
10331040 if let Some ( name) = name {
1034- format_to ! ( buf, "has an associated constant `{}`" , name. as_str( ) ) ;
1041+ format_to ! ( buf, "having an associated constant `{}`" , name. as_str( ) ) ;
10351042 } else {
1036- buf. push_str ( "has an associated constant" ) ;
1043+ buf. push_str ( "having an associated constant" ) ;
10371044 }
10381045 }
10391046 DynCompatibilityViolation :: GAT ( alias) => {
10401047 let name = hir:: TypeAlias :: from ( alias) . name ( db) ;
1041- format_to ! ( buf, "has a generic associated type `{}`" , name. as_str( ) ) ;
1048+ format_to ! ( buf, "having a generic associated type `{}`" , name. as_str( ) ) ;
10421049 }
10431050 DynCompatibilityViolation :: HasNonCompatibleSuperTrait ( super_trait) => {
10441051 let name = hir:: Trait :: from ( super_trait) . name ( db) ;
1045- format_to ! ( buf, "has a dyn incompatible supertrait `{}`" , name. as_str( ) ) ;
1052+ format_to ! ( buf, "having a dyn incompatible supertrait `{}`" , name. as_str( ) ) ;
10461053 }
10471054 }
10481055}
0 commit comments