@@ -630,27 +630,57 @@ pub(super) fn definition(
630630 }
631631 } ,
632632 |_| None ,
633+ |_| None ,
634+ ) ,
635+ Definition :: Adt ( it @ Adt :: Struct ( strukt) ) => render_memory_layout (
636+ config. memory_layout ,
637+ || it. layout ( db) ,
638+ |_| None ,
639+ |layout| {
640+ let mut field_size =
641+ |i : usize | Some ( strukt. fields ( db) . get ( i) ?. layout ( db) . ok ( ) ?. size ( ) ) ;
642+ if strukt. repr ( db) . is_some_and ( |it| it. inhibit_struct_field_reordering ( ) ) {
643+ Some ( ( "tail padding" , layout. tail_padding ( & mut field_size) ?) )
644+ } else {
645+ Some ( ( "largest padding" , layout. largest_padding ( & mut field_size) ?) )
646+ }
647+ } ,
648+ |_| None ,
649+ ) ,
650+ Definition :: Adt ( it) => render_memory_layout (
651+ config. memory_layout ,
652+ || it. layout ( db) ,
653+ |_| None ,
654+ |_| None ,
655+ |_| None ,
633656 ) ,
634- Definition :: Adt ( it) => {
635- render_memory_layout ( config. memory_layout , || it. layout ( db) , |_| None , |_| None )
636- }
637657 Definition :: Variant ( it) => render_memory_layout (
638658 config. memory_layout ,
639659 || it. layout ( db) ,
640660 |_| None ,
661+ |_| None ,
641662 |layout| layout. enum_tag_size ( ) ,
642663 ) ,
643- Definition :: TypeAlias ( it) => {
644- render_memory_layout ( config. memory_layout , || it. ty ( db) . layout ( db) , |_| None , |_| None )
645- }
646- Definition :: Local ( it) => {
647- render_memory_layout ( config. memory_layout , || it. ty ( db) . layout ( db) , |_| None , |_| None )
648- }
664+ Definition :: TypeAlias ( it) => render_memory_layout (
665+ config. memory_layout ,
666+ || it. ty ( db) . layout ( db) ,
667+ |_| None ,
668+ |_| None ,
669+ |_| None ,
670+ ) ,
671+ Definition :: Local ( it) => render_memory_layout (
672+ config. memory_layout ,
673+ || it. ty ( db) . layout ( db) ,
674+ |_| None ,
675+ |_| None ,
676+ |_| None ,
677+ ) ,
649678 Definition :: SelfType ( it) => render_memory_layout (
650679 config. memory_layout ,
651680 || it. self_ty ( db) . layout ( db) ,
652681 |_| None ,
653682 |_| None ,
683+ |_| None ,
654684 ) ,
655685 _ => None ,
656686 } ;
@@ -1055,9 +1085,13 @@ fn closure_ty(
10551085 if let Some ( trait_) = c. fn_trait ( sema. db ) . get_id ( sema. db , original. krate ( sema. db ) . into ( ) ) {
10561086 push_new_def ( hir:: Trait :: from ( trait_) . into ( ) )
10571087 }
1058- if let Some ( layout) =
1059- render_memory_layout ( config. memory_layout , || original. layout ( sema. db ) , |_| None , |_| None )
1060- {
1088+ if let Some ( layout) = render_memory_layout (
1089+ config. memory_layout ,
1090+ || original. layout ( sema. db ) ,
1091+ |_| None ,
1092+ |_| None ,
1093+ |_| None ,
1094+ ) {
10611095 format_to ! ( markup, "\n ___\n {layout}" ) ;
10621096 }
10631097 format_to ! ( markup, "{adjusted}\n \n ## Captures\n {}" , captures_rendered, ) ;
@@ -1142,6 +1176,7 @@ fn render_memory_layout(
11421176 config : Option < MemoryLayoutHoverConfig > ,
11431177 layout : impl FnOnce ( ) -> Result < Layout , LayoutError > ,
11441178 offset : impl FnOnce ( & Layout ) -> Option < u64 > ,
1179+ padding : impl FnOnce ( & Layout ) -> Option < ( & str , u64 ) > ,
11451180 tag : impl FnOnce ( & Layout ) -> Option < usize > ,
11461181) -> Option < String > {
11471182 let config = config?;
@@ -1199,6 +1234,23 @@ fn render_memory_layout(
11991234 }
12001235 }
12011236
1237+ if let Some ( render) = config. padding {
1238+ if let Some ( ( padding_name, padding) ) = padding ( & layout) {
1239+ format_to ! ( label, "{padding_name} = " ) ;
1240+ match render {
1241+ MemoryLayoutHoverRenderKind :: Decimal => format_to ! ( label, "{padding}" ) ,
1242+ MemoryLayoutHoverRenderKind :: Hexadecimal => format_to ! ( label, "{padding:#X}" ) ,
1243+ MemoryLayoutHoverRenderKind :: Both if padding >= 10 => {
1244+ format_to ! ( label, "{padding} ({padding:#X})" )
1245+ }
1246+ MemoryLayoutHoverRenderKind :: Both => {
1247+ format_to ! ( label, "{padding}" )
1248+ }
1249+ }
1250+ format_to ! ( label, ", " ) ;
1251+ }
1252+ }
1253+
12021254 if config. niches {
12031255 if let Some ( niches) = layout. niches ( ) {
12041256 if niches > 1024 {
0 commit comments