@@ -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,29 +530,32 @@ 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
540542 let mut desc = String :: new ( ) ;
541543 if let Some ( notable_traits) = render_notable_trait_comment ( db, notable_traits, edition) {
542544 desc. push_str ( & notable_traits) ;
543545 desc. push ( '\n' ) ;
544546 }
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' ) ;
547+ if hovered_definition {
548+ if let Some ( layout_info) = layout_info ( ) {
549+ desc. push_str ( & layout_info) ;
550+ desc. push ( '\n' ) ;
551+ }
552+ if let Some ( dyn_compatibility_info) = dyn_compatibility_info ( ) {
553+ desc. push_str ( & dyn_compatibility_info) ;
554+ desc. push ( '\n' ) ;
555+ }
552556 }
553557 desc. push_str ( & label) ;
554- if let Some ( value) = value {
558+ if let Some ( value) = value ( ) {
555559 desc. push_str ( " = " ) ;
556560 desc. push_str ( & value) ;
557561 }
@@ -994,55 +998,53 @@ fn render_dyn_compatibility(
994998 safety : Option < DynCompatibilityViolation > ,
995999) {
9961000 let Some ( osv) = safety else {
997- buf. push_str ( "// Dyn Compatible: Yes " ) ;
1001+ buf. push_str ( "// Is Dyn compatible " ) ;
9981002 return ;
9991003 } ;
1000- buf. push_str ( "// Dyn Compatible: No \n // - Reason: " ) ;
1004+ buf. push_str ( "// Is not Dyn compatible due to " ) ;
10011005 match osv {
10021006 DynCompatibilityViolation :: SizedSelf => {
1003- buf. push_str ( "has a `Self: Sized` bound" ) ;
1007+ buf. push_str ( "having a `Self: Sized` bound" ) ;
10041008 }
10051009 DynCompatibilityViolation :: SelfReferential => {
1006- buf. push_str ( "has a bound that references `Self`" ) ;
1010+ buf. push_str ( "having a bound that references `Self`" ) ;
10071011 }
10081012 DynCompatibilityViolation :: Method ( func, mvc) => {
10091013 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- ) ;
1014+ format_to ! ( buf, "having a method `{}` that is not dispatchable due to " , name. as_str( ) ) ;
10151015 let desc = match mvc {
10161016 MethodViolationCode :: StaticMethod => "missing a receiver" ,
1017- MethodViolationCode :: ReferencesSelfInput => "a parameter references `Self`" ,
1018- MethodViolationCode :: ReferencesSelfOutput => "the return type references `Self`" ,
1017+ MethodViolationCode :: ReferencesSelfInput => "having a parameter referencing `Self`" ,
1018+ MethodViolationCode :: ReferencesSelfOutput => "the return type referencing `Self`" ,
10191019 MethodViolationCode :: ReferencesImplTraitInTrait => {
1020- "the return type contains `impl Trait`"
1020+ "the return type containing `impl Trait`"
10211021 }
10221022 MethodViolationCode :: AsyncFn => "being async" ,
10231023 MethodViolationCode :: WhereClauseReferencesSelf => {
1024- "a where clause references `Self`"
1024+ "a where clause referencing `Self`"
1025+ }
1026+ MethodViolationCode :: Generic => "having a const or type generic parameter" ,
1027+ MethodViolationCode :: UndispatchableReceiver => {
1028+ "having a non-dispatchable receiver type"
10251029 }
1026- MethodViolationCode :: Generic => "a non-lifetime generic parameter" ,
1027- MethodViolationCode :: UndispatchableReceiver => "a non-dispatchable receiver type" ,
10281030 } ;
10291031 buf. push_str ( desc) ;
10301032 }
10311033 DynCompatibilityViolation :: AssocConst ( const_) => {
10321034 let name = hir:: Const :: from ( const_) . name ( db) ;
10331035 if let Some ( name) = name {
1034- format_to ! ( buf, "has an associated constant `{}`" , name. as_str( ) ) ;
1036+ format_to ! ( buf, "having an associated constant `{}`" , name. as_str( ) ) ;
10351037 } else {
1036- buf. push_str ( "has an associated constant" ) ;
1038+ buf. push_str ( "having an associated constant" ) ;
10371039 }
10381040 }
10391041 DynCompatibilityViolation :: GAT ( alias) => {
10401042 let name = hir:: TypeAlias :: from ( alias) . name ( db) ;
1041- format_to ! ( buf, "has a generic associated type `{}`" , name. as_str( ) ) ;
1043+ format_to ! ( buf, "having a generic associated type `{}`" , name. as_str( ) ) ;
10421044 }
10431045 DynCompatibilityViolation :: HasNonCompatibleSuperTrait ( super_trait) => {
10441046 let name = hir:: Trait :: from ( super_trait) . name ( db) ;
1045- format_to ! ( buf, "has a dyn incompatible supertrait `{}`" , name. as_str( ) ) ;
1047+ format_to ! ( buf, "having a dyn incompatible supertrait `{}`" , name. as_str( ) ) ;
10461048 }
10471049 }
10481050}
0 commit comments