@@ -230,7 +230,7 @@ struct TransformVisitor<'tcx> {
230
230
231
231
// Mapping from Local to (type of local, generator struct index)
232
232
// FIXME(eddyb) This should use `IndexVec<Local, Option<_>>`.
233
- remap : FxHashMap < Local , ( Ty < ' tcx > , VariantIdx , usize ) > ,
233
+ remap : FxHashMap < Local , ( Ty < ' tcx > , VariantIdx , FieldIdx ) > ,
234
234
235
235
// A map from a suspension point in a block to the locals which have live storage at that point
236
236
storage_liveness : IndexVec < BasicBlock , Option < BitSet < Local > > > ,
@@ -295,11 +295,11 @@ impl<'tcx> TransformVisitor<'tcx> {
295
295
}
296
296
297
297
// Create a Place referencing a generator struct field
298
- fn make_field ( & self , variant_index : VariantIdx , idx : usize , ty : Ty < ' tcx > ) -> Place < ' tcx > {
298
+ fn make_field ( & self , variant_index : VariantIdx , idx : FieldIdx , ty : Ty < ' tcx > ) -> Place < ' tcx > {
299
299
let self_place = Place :: from ( SELF_ARG ) ;
300
300
let base = self . tcx . mk_place_downcast_unnamed ( self_place, variant_index) ;
301
301
let mut projection = base. projection . to_vec ( ) ;
302
- projection. push ( ProjectionElem :: Field ( FieldIdx :: new ( idx) , ty) ) ;
302
+ projection. push ( ProjectionElem :: Field ( idx, ty) ) ;
303
303
304
304
Place { local : base. local , projection : self . tcx . mk_place_elems ( & projection) }
305
305
}
@@ -904,7 +904,7 @@ fn compute_layout<'tcx>(
904
904
liveness : LivenessInfo ,
905
905
body : & Body < ' tcx > ,
906
906
) -> (
907
- FxHashMap < Local , ( Ty < ' tcx > , VariantIdx , usize ) > ,
907
+ FxHashMap < Local , ( Ty < ' tcx > , VariantIdx , FieldIdx ) > ,
908
908
GeneratorLayout < ' tcx > ,
909
909
IndexVec < BasicBlock , Option < BitSet < Local > > > ,
910
910
) {
@@ -982,6 +982,7 @@ fn compute_layout<'tcx>(
982
982
// just use the first one here. That's fine; fields do not move
983
983
// around inside generators, so it doesn't matter which variant
984
984
// index we access them by.
985
+ let idx = FieldIdx :: from_usize ( idx) ;
985
986
remap. entry ( locals[ saved_local] ) . or_insert ( ( tys[ saved_local] . ty , variant_index, idx) ) ;
986
987
}
987
988
variant_fields. push ( fields) ;
@@ -990,8 +991,23 @@ fn compute_layout<'tcx>(
990
991
debug ! ( "generator variant_fields = {:?}" , variant_fields) ;
991
992
debug ! ( "generator storage_conflicts = {:#?}" , storage_conflicts) ;
992
993
993
- let layout =
994
- GeneratorLayout { field_tys : tys, variant_fields, variant_source_info, storage_conflicts } ;
994
+ let mut field_names = IndexVec :: from_elem ( None , & tys) ;
995
+ for var in & body. var_debug_info {
996
+ let VarDebugInfoContents :: Place ( place) = & var. value else { continue } ;
997
+ let Some ( local) = place. as_local ( ) else { continue } ;
998
+ let Some ( & ( _, variant, field) ) = remap. get ( & local) else { continue } ;
999
+
1000
+ let saved_local = variant_fields[ variant] [ field] ;
1001
+ field_names. get_or_insert_with ( saved_local, || var. name ) ;
1002
+ }
1003
+
1004
+ let layout = GeneratorLayout {
1005
+ field_tys : tys,
1006
+ field_names,
1007
+ variant_fields,
1008
+ variant_source_info,
1009
+ storage_conflicts,
1010
+ } ;
995
1011
debug ! ( ?layout) ;
996
1012
997
1013
( remap, layout, storage_liveness)
0 commit comments