@@ -419,6 +419,7 @@ pub(super) fn definition(
419
419
famous_defs : Option < & FamousDefs < ' _ , ' _ > > ,
420
420
notable_traits : & [ ( Trait , Vec < ( Option < Type > , Name ) > ) ] ,
421
421
macro_arm : Option < u32 > ,
422
+ hovered_definition : bool ,
422
423
config : & HoverConfig ,
423
424
edition : Edition ,
424
425
) -> Markup {
@@ -456,7 +457,7 @@ pub(super) fn definition(
456
457
_ => def. label ( db, edition) ,
457
458
} ;
458
459
let docs = def. docs ( db, famous_defs, edition) ;
459
- let value = ( || match def {
460
+ let value = || match def {
460
461
Definition :: Variant ( it) => {
461
462
if !it. parent_enum ( db) . is_data_carrying ( db) {
462
463
match it. eval ( db) {
@@ -494,9 +495,9 @@ pub(super) fn definition(
494
495
Some ( body. to_string ( ) )
495
496
}
496
497
_ => None ,
497
- } ) ( ) ;
498
+ } ;
498
499
499
- let layout_info = match def {
500
+ let layout_info = || match def {
500
501
Definition :: Field ( it) => render_memory_layout (
501
502
config. memory_layout ,
502
503
|| it. layout ( db) ,
@@ -529,29 +530,32 @@ pub(super) fn definition(
529
530
_ => None ,
530
531
} ;
531
532
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 ,
538
540
} ;
539
541
540
542
let mut desc = String :: new ( ) ;
541
543
if let Some ( notable_traits) = render_notable_trait_comment ( db, notable_traits, edition) {
542
544
desc. push_str ( & notable_traits) ;
543
545
desc. push ( '\n' ) ;
544
546
}
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
+ }
552
556
}
553
557
desc. push_str ( & label) ;
554
- if let Some ( value) = value {
558
+ if let Some ( value) = value ( ) {
555
559
desc. push_str ( " = " ) ;
556
560
desc. push_str ( & value) ;
557
561
}
@@ -994,55 +998,53 @@ fn render_dyn_compatibility(
994
998
safety : Option < DynCompatibilityViolation > ,
995
999
) {
996
1000
let Some ( osv) = safety else {
997
- buf. push_str ( "// Dyn Compatible: Yes " ) ;
1001
+ buf. push_str ( "// Is Dyn compatible " ) ;
998
1002
return ;
999
1003
} ;
1000
- buf. push_str ( "// Dyn Compatible: No \n // - Reason: " ) ;
1004
+ buf. push_str ( "// Is not Dyn compatible due to " ) ;
1001
1005
match osv {
1002
1006
DynCompatibilityViolation :: SizedSelf => {
1003
- buf. push_str ( "has a `Self: Sized` bound" ) ;
1007
+ buf. push_str ( "having a `Self: Sized` bound" ) ;
1004
1008
}
1005
1009
DynCompatibilityViolation :: SelfReferential => {
1006
- buf. push_str ( "has a bound that references `Self`" ) ;
1010
+ buf. push_str ( "having a bound that references `Self`" ) ;
1007
1011
}
1008
1012
DynCompatibilityViolation :: Method ( func, mvc) => {
1009
1013
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( ) ) ;
1015
1015
let desc = match mvc {
1016
1016
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`" ,
1019
1019
MethodViolationCode :: ReferencesImplTraitInTrait => {
1020
- "the return type contains `impl Trait`"
1020
+ "the return type containing `impl Trait`"
1021
1021
}
1022
1022
MethodViolationCode :: AsyncFn => "being async" ,
1023
1023
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"
1025
1029
}
1026
- MethodViolationCode :: Generic => "a non-lifetime generic parameter" ,
1027
- MethodViolationCode :: UndispatchableReceiver => "a non-dispatchable receiver type" ,
1028
1030
} ;
1029
1031
buf. push_str ( desc) ;
1030
1032
}
1031
1033
DynCompatibilityViolation :: AssocConst ( const_) => {
1032
1034
let name = hir:: Const :: from ( const_) . name ( db) ;
1033
1035
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( ) ) ;
1035
1037
} else {
1036
- buf. push_str ( "has an associated constant" ) ;
1038
+ buf. push_str ( "having an associated constant" ) ;
1037
1039
}
1038
1040
}
1039
1041
DynCompatibilityViolation :: GAT ( alias) => {
1040
1042
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( ) ) ;
1042
1044
}
1043
1045
DynCompatibilityViolation :: HasNonCompatibleSuperTrait ( super_trait) => {
1044
1046
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( ) ) ;
1046
1048
}
1047
1049
}
1048
1050
}
0 commit comments