@@ -630,27 +630,57 @@ pub(super) fn definition(
630
630
}
631
631
} ,
632
632
|_| 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 ,
633
656
) ,
634
- Definition :: Adt ( it) => {
635
- render_memory_layout ( config. memory_layout , || it. layout ( db) , |_| None , |_| None )
636
- }
637
657
Definition :: Variant ( it) => render_memory_layout (
638
658
config. memory_layout ,
639
659
|| it. layout ( db) ,
640
660
|_| None ,
661
+ |_| None ,
641
662
|layout| layout. enum_tag_size ( ) ,
642
663
) ,
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
+ ) ,
649
678
Definition :: SelfType ( it) => render_memory_layout (
650
679
config. memory_layout ,
651
680
|| it. self_ty ( db) . layout ( db) ,
652
681
|_| None ,
653
682
|_| None ,
683
+ |_| None ,
654
684
) ,
655
685
_ => None ,
656
686
} ;
@@ -1055,9 +1085,13 @@ fn closure_ty(
1055
1085
if let Some ( trait_) = c. fn_trait ( sema. db ) . get_id ( sema. db , original. krate ( sema. db ) . into ( ) ) {
1056
1086
push_new_def ( hir:: Trait :: from ( trait_) . into ( ) )
1057
1087
}
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
+ ) {
1061
1095
format_to ! ( markup, "\n ___\n {layout}" ) ;
1062
1096
}
1063
1097
format_to ! ( markup, "{adjusted}\n \n ## Captures\n {}" , captures_rendered, ) ;
@@ -1142,6 +1176,7 @@ fn render_memory_layout(
1142
1176
config : Option < MemoryLayoutHoverConfig > ,
1143
1177
layout : impl FnOnce ( ) -> Result < Layout , LayoutError > ,
1144
1178
offset : impl FnOnce ( & Layout ) -> Option < u64 > ,
1179
+ padding : impl FnOnce ( & Layout ) -> Option < ( & str , u64 ) > ,
1145
1180
tag : impl FnOnce ( & Layout ) -> Option < usize > ,
1146
1181
) -> Option < String > {
1147
1182
let config = config?;
@@ -1199,6 +1234,23 @@ fn render_memory_layout(
1199
1234
}
1200
1235
}
1201
1236
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
+
1202
1254
if config. niches {
1203
1255
if let Some ( niches) = layout. niches ( ) {
1204
1256
if niches > 1024 {
0 commit comments