@@ -43,13 +43,17 @@ pub(super) fn type_info_of(
43
43
44
44
pub ( super ) fn closure_expr (
45
45
sema : & Semantics < ' _ , RootDatabase > ,
46
+ config : & HoverConfig ,
46
47
c : ast:: ClosureExpr ,
47
48
) -> Option < HoverResult > {
48
49
let ty = & sema. type_of_expr ( & c. into ( ) ) ?. original ;
49
- let layout = ty
50
- . layout ( sema. db )
51
- . map ( |x| format ! ( " // size = {}, align = {}" , x. size. bytes( ) , x. align. abi. bytes( ) ) )
52
- . unwrap_or_default ( ) ;
50
+ let layout = if config. memory_layout {
51
+ ty. layout ( sema. db )
52
+ . map ( |x| format ! ( " // size = {}, align = {}" , x. size. bytes( ) , x. align. abi. bytes( ) ) )
53
+ . unwrap_or_default ( )
54
+ } else {
55
+ String :: default ( )
56
+ } ;
53
57
let c = ty. as_closure ( ) ?;
54
58
let mut captures = c
55
59
. captured_items ( sema. db )
@@ -415,7 +419,7 @@ pub(super) fn definition(
415
419
let mod_path = definition_mod_path ( db, & def) ;
416
420
let ( label, docs) = match def {
417
421
Definition :: Macro ( it) => label_and_docs ( db, it) ,
418
- Definition :: Field ( it) => label_and_layout_info_and_docs ( db, it, |& it| {
422
+ Definition :: Field ( it) => label_and_layout_info_and_docs ( db, it, config , |& it| {
419
423
let var_def = it. parent_def ( db) ;
420
424
let id = it. index ( ) ;
421
425
let layout = it. layout ( db) . ok ( ) ?;
@@ -435,7 +439,7 @@ pub(super) fn definition(
435
439
} ) ,
436
440
Definition :: Module ( it) => label_and_docs ( db, it) ,
437
441
Definition :: Function ( it) => label_and_docs ( db, it) ,
438
- Definition :: Adt ( it) => label_and_layout_info_and_docs ( db, it, |& it| {
442
+ Definition :: Adt ( it) => label_and_layout_info_and_docs ( db, it, config , |& it| {
439
443
let layout = it. layout ( db) . ok ( ) ?;
440
444
Some ( format ! ( "size = {}, align = {}" , layout. size. bytes( ) , layout. align. abi. bytes( ) ) )
441
445
} ) ,
@@ -473,7 +477,7 @@ pub(super) fn definition(
473
477
} ) ,
474
478
Definition :: Trait ( it) => label_and_docs ( db, it) ,
475
479
Definition :: TraitAlias ( it) => label_and_docs ( db, it) ,
476
- Definition :: TypeAlias ( it) => label_and_layout_info_and_docs ( db, it, |& it| {
480
+ Definition :: TypeAlias ( it) => label_and_layout_info_and_docs ( db, it, config , |& it| {
477
481
let layout = it. ty ( db) . layout ( db) . ok ( ) ?;
478
482
Some ( format ! ( "size = {}, align = {}" , layout. size. bytes( ) , layout. align. abi. bytes( ) ) )
479
483
} ) ,
@@ -577,17 +581,17 @@ where
577
581
fn label_and_layout_info_and_docs < D , E , V > (
578
582
db : & RootDatabase ,
579
583
def : D ,
584
+ config : & HoverConfig ,
580
585
value_extractor : E ,
581
586
) -> ( String , Option < hir:: Documentation > )
582
587
where
583
588
D : HasAttrs + HirDisplay ,
584
589
E : Fn ( & D ) -> Option < V > ,
585
590
V : Display ,
586
591
{
587
- let label = if let Some ( value) = value_extractor ( & def) {
588
- format ! ( "{} // {value}" , def. display( db) )
589
- } else {
590
- def. display ( db) . to_string ( )
592
+ let label = match value_extractor ( & def) {
593
+ Some ( value) if config. memory_layout => format ! ( "{} // {value}" , def. display( db) ) ,
594
+ _ => def. display ( db) . to_string ( ) ,
591
595
} ;
592
596
let docs = def. attrs ( db) . docs ( ) ;
593
597
( label, docs)
0 commit comments