@@ -43,13 +43,17 @@ pub(super) fn type_info_of(
4343
4444pub ( super ) fn closure_expr (
4545 sema : & Semantics < ' _ , RootDatabase > ,
46+ config : & HoverConfig ,
4647 c : ast:: ClosureExpr ,
4748) -> Option < HoverResult > {
4849 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+ } ;
5357 let c = ty. as_closure ( ) ?;
5458 let mut captures = c
5559 . captured_items ( sema. db )
@@ -415,7 +419,7 @@ pub(super) fn definition(
415419 let mod_path = definition_mod_path ( db, & def) ;
416420 let ( label, docs) = match def {
417421 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| {
419423 let var_def = it. parent_def ( db) ;
420424 let id = it. index ( ) ;
421425 let layout = it. layout ( db) . ok ( ) ?;
@@ -435,7 +439,7 @@ pub(super) fn definition(
435439 } ) ,
436440 Definition :: Module ( it) => label_and_docs ( db, it) ,
437441 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| {
439443 let layout = it. layout ( db) . ok ( ) ?;
440444 Some ( format ! ( "size = {}, align = {}" , layout. size. bytes( ) , layout. align. abi. bytes( ) ) )
441445 } ) ,
@@ -473,7 +477,7 @@ pub(super) fn definition(
473477 } ) ,
474478 Definition :: Trait ( it) => label_and_docs ( db, it) ,
475479 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| {
477481 let layout = it. ty ( db) . layout ( db) . ok ( ) ?;
478482 Some ( format ! ( "size = {}, align = {}" , layout. size. bytes( ) , layout. align. abi. bytes( ) ) )
479483 } ) ,
@@ -577,17 +581,17 @@ where
577581fn label_and_layout_info_and_docs < D , E , V > (
578582 db : & RootDatabase ,
579583 def : D ,
584+ config : & HoverConfig ,
580585 value_extractor : E ,
581586) -> ( String , Option < hir:: Documentation > )
582587where
583588 D : HasAttrs + HirDisplay ,
584589 E : Fn ( & D ) -> Option < V > ,
585590 V : Display ,
586591{
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 ( ) ,
591595 } ;
592596 let docs = def. attrs ( db) . docs ( ) ;
593597 ( label, docs)
0 commit comments