@@ -14,22 +14,26 @@ use std::iter::TrustedLen;
14
14
/// (lhs as Variant).field1 = arg1;
15
15
/// discriminant(lhs) = variant_index; // If lhs is an enum or generator.
16
16
pub fn expand_aggregate < ' tcx > (
17
- mut lhs : Place < ' tcx > ,
17
+ orig_lhs : Place < ' tcx > ,
18
18
operands : impl Iterator < Item = ( Operand < ' tcx > , Ty < ' tcx > ) > + TrustedLen ,
19
19
kind : AggregateKind < ' tcx > ,
20
20
source_info : SourceInfo ,
21
21
tcx : TyCtxt < ' tcx > ,
22
22
) -> impl Iterator < Item = Statement < ' tcx > > + TrustedLen {
23
+ let mut lhs = orig_lhs;
23
24
let mut set_discriminant = None ;
24
25
let active_field_index = match kind {
25
26
AggregateKind :: Adt ( adt_did, variant_index, _, _, active_field_index) => {
26
27
let adt_def = tcx. adt_def ( adt_did) ;
27
28
if adt_def. is_enum ( ) {
28
29
set_discriminant = Some ( Statement {
29
- kind : StatementKind :: SetDiscriminant { place : Box :: new ( lhs) , variant_index } ,
30
+ kind : StatementKind :: SetDiscriminant {
31
+ place : Box :: new ( orig_lhs) ,
32
+ variant_index,
33
+ } ,
30
34
source_info,
31
35
} ) ;
32
- lhs = tcx. mk_place_downcast ( lhs , adt_def, variant_index) ;
36
+ lhs = tcx. mk_place_downcast ( orig_lhs , adt_def, variant_index) ;
33
37
}
34
38
active_field_index
35
39
}
@@ -38,7 +42,7 @@ pub fn expand_aggregate<'tcx>(
38
42
// variant 0 (Unresumed).
39
43
let variant_index = VariantIdx :: new ( 0 ) ;
40
44
set_discriminant = Some ( Statement {
41
- kind : StatementKind :: SetDiscriminant { place : Box :: new ( lhs ) , variant_index } ,
45
+ kind : StatementKind :: SetDiscriminant { place : Box :: new ( orig_lhs ) , variant_index } ,
42
46
source_info,
43
47
} ) ;
44
48
@@ -50,27 +54,24 @@ pub fn expand_aggregate<'tcx>(
50
54
_ => None ,
51
55
} ;
52
56
53
- operands
54
- . enumerate ( )
55
- . map ( move |( i, ( op, ty) ) | {
56
- let lhs_field = if let AggregateKind :: Array ( _) = kind {
57
- let offset = u64:: try_from ( i) . unwrap ( ) ;
58
- tcx. mk_place_elem (
59
- lhs,
60
- ProjectionElem :: ConstantIndex {
61
- offset,
62
- min_length : offset + 1 ,
63
- from_end : false ,
64
- } ,
65
- )
66
- } else {
67
- let field = Field :: new ( active_field_index. unwrap_or ( i) ) ;
68
- tcx. mk_place_field ( lhs, field, ty)
69
- } ;
70
- Statement {
71
- source_info,
72
- kind : StatementKind :: Assign ( Box :: new ( ( lhs_field, Rvalue :: Use ( op) ) ) ) ,
73
- }
74
- } )
57
+ let operands = operands. enumerate ( ) . map ( move |( i, ( op, ty) ) | {
58
+ let lhs_field = if let AggregateKind :: Array ( _) = kind {
59
+ let offset = u64:: try_from ( i) . unwrap ( ) ;
60
+ tcx. mk_place_elem (
61
+ lhs,
62
+ ProjectionElem :: ConstantIndex { offset, min_length : offset + 1 , from_end : false } ,
63
+ )
64
+ } else {
65
+ let field = Field :: new ( active_field_index. unwrap_or ( i) ) ;
66
+ tcx. mk_place_field ( lhs, field, ty)
67
+ } ;
68
+ Statement {
69
+ source_info,
70
+ kind : StatementKind :: Assign ( Box :: new ( ( lhs_field, Rvalue :: Use ( op) ) ) ) ,
71
+ }
72
+ } ) ;
73
+ [ Statement { source_info, kind : StatementKind :: Deinit ( Box :: new ( orig_lhs) ) } ]
74
+ . into_iter ( )
75
+ . chain ( operands)
75
76
. chain ( set_discriminant)
76
77
}
0 commit comments