@@ -8,7 +8,7 @@ use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
88use rustc_session:: config:: DebugInfo ;
99use rustc_span:: symbol:: { kw, Symbol } ;
1010use rustc_span:: { BytePos , Span } ;
11- use rustc_target:: abi:: { Abi , FieldIdx , Size , VariantIdx } ;
11+ use rustc_target:: abi:: { Abi , FieldIdx , FieldsShape , Size , VariantIdx } ;
1212
1313use super :: operand:: { OperandRef , OperandValue } ;
1414use super :: place:: PlaceRef ;
@@ -83,6 +83,7 @@ trait DebugInfoOffsetLocation<'tcx, Bx> {
8383 fn deref ( & self , bx : & mut Bx ) -> Self ;
8484 fn layout ( & self ) -> TyAndLayout < ' tcx > ;
8585 fn project_field ( & self , bx : & mut Bx , field : FieldIdx ) -> Self ;
86+ fn project_constant_index ( & self , bx : & mut Bx , offset : u64 ) -> Self ;
8687 fn downcast ( & self , bx : & mut Bx , variant : VariantIdx ) -> Self ;
8788}
8889
@@ -101,6 +102,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> DebugInfoOffsetLocation<'tcx, Bx>
101102 PlaceRef :: project_field ( * self , bx, field. index ( ) )
102103 }
103104
105+ fn project_constant_index ( & self , bx : & mut Bx , offset : u64 ) -> Self {
106+ let lloffset = bx. cx ( ) . const_usize ( offset) ;
107+ self . project_index ( bx, lloffset)
108+ }
109+
104110 fn downcast ( & self , bx : & mut Bx , variant : VariantIdx ) -> Self {
105111 self . project_downcast ( bx, variant)
106112 }
@@ -123,6 +129,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> DebugInfoOffsetLocation<'tcx, Bx>
123129 self . field ( bx. cx ( ) , field. index ( ) )
124130 }
125131
132+ fn project_constant_index ( & self , bx : & mut Bx , index : u64 ) -> Self {
133+ self . field ( bx. cx ( ) , index as usize )
134+ }
135+
126136 fn downcast ( & self , bx : & mut Bx , variant : VariantIdx ) -> Self {
127137 self . for_variant ( bx. cx ( ) , variant)
128138 }
@@ -168,6 +178,18 @@ fn calculate_debuginfo_offset<
168178 mir:: ProjectionElem :: Downcast ( _, variant) => {
169179 place = place. downcast ( bx, variant) ;
170180 }
181+ mir:: ProjectionElem :: ConstantIndex {
182+ offset : index,
183+ min_length : _,
184+ from_end : false ,
185+ } => {
186+ let offset = indirect_offsets. last_mut ( ) . unwrap_or ( & mut direct_offset) ;
187+ let FieldsShape :: Array { stride, count : _ } = place. layout ( ) . fields else {
188+ span_bug ! ( var. source_info. span, "ConstantIndex on non-array type {:?}" , place. layout( ) )
189+ } ;
190+ * offset += stride * index;
191+ place = place. project_constant_index ( bx, index) ;
192+ }
171193 _ => {
172194 // Sanity check for `can_use_in_debuginfo`.
173195 debug_assert ! ( !elem. can_use_in_debuginfo( ) ) ;
0 commit comments