@@ -1181,26 +1181,37 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1181
1181
// We need to report back the list of mutable upvars that were
1182
1182
// moved into the closure and subsequently used by the closure,
1183
1183
// in order to populate our used_mut set.
1184
- if let AggregateKind :: Closure ( def_id, _) = & * * aggregate_kind {
1185
- let BorrowCheckResult {
1186
- used_mut_upvars, ..
1187
- } = self . tcx . mir_borrowck ( * def_id) ;
1188
- debug ! ( "{:?} used_mut_upvars={:?}" , def_id, used_mut_upvars) ;
1189
- for field in used_mut_upvars {
1190
- match operands[ field. index ( ) ] {
1191
- Operand :: Move ( Place :: Local ( local) ) => {
1192
- self . used_mut . insert ( local) ;
1193
- }
1194
- Operand :: Move ( ref place @ Place :: Projection ( _) ) => {
1195
- if let Some ( field) = self . is_upvar_field_projection ( place) {
1196
- self . used_mut_upvars . push ( field) ;
1184
+ match * * aggregate_kind {
1185
+ AggregateKind :: Closure ( def_id, _)
1186
+ | AggregateKind :: Generator ( def_id, _, _) => {
1187
+ let BorrowCheckResult {
1188
+ used_mut_upvars, ..
1189
+ } = self . tcx . mir_borrowck ( def_id) ;
1190
+ debug ! ( "{:?} used_mut_upvars={:?}" , def_id, used_mut_upvars) ;
1191
+ for field in used_mut_upvars {
1192
+ // This relies on the current way that by-value
1193
+ // captures of a closure are copied/moved directly
1194
+ // when generating MIR.
1195
+ match operands[ field. index ( ) ] {
1196
+ Operand :: Move ( Place :: Local ( local) )
1197
+ | Operand :: Copy ( Place :: Local ( local) ) => {
1198
+ self . used_mut . insert ( local) ;
1199
+ }
1200
+ Operand :: Move ( ref place @ Place :: Projection ( _) )
1201
+ | Operand :: Copy ( ref place @ Place :: Projection ( _) ) => {
1202
+ if let Some ( field) = self . is_upvar_field_projection ( place) {
1203
+ self . used_mut_upvars . push ( field) ;
1204
+ }
1197
1205
}
1206
+ Operand :: Move ( Place :: Static ( ..) )
1207
+ | Operand :: Copy ( Place :: Static ( ..) )
1208
+ | Operand :: Constant ( ..) => { }
1198
1209
}
1199
- Operand :: Move ( Place :: Static ( ..) )
1200
- | Operand :: Copy ( ..)
1201
- | Operand :: Constant ( ..) => { }
1202
1210
}
1203
1211
}
1212
+ AggregateKind :: Adt ( ..)
1213
+ | AggregateKind :: Array ( ..)
1214
+ | AggregateKind :: Tuple { .. } => ( ) ,
1204
1215
}
1205
1216
1206
1217
for operand in operands {
@@ -1939,6 +1950,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1939
1950
}
1940
1951
}
1941
1952
}
1953
+ RootPlace {
1954
+ place : _,
1955
+ is_local_mutation_allowed : LocalMutationIsAllowed :: Yes ,
1956
+ } => { }
1942
1957
RootPlace {
1943
1958
place : place @ Place :: Projection ( _) ,
1944
1959
is_local_mutation_allowed : _,
@@ -2114,13 +2129,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
2114
2129
match * place {
2115
2130
Place :: Projection ( ref proj) => match proj. elem {
2116
2131
ProjectionElem :: Field ( field, _ty) => {
2117
- let is_projection_from_ty_closure = proj
2118
- . base
2119
- . ty ( self . mir , self . tcx )
2120
- . to_ty ( self . tcx )
2121
- . is_closure ( ) ;
2132
+ let base_ty = proj. base . ty ( self . mir , self . tcx ) . to_ty ( self . tcx ) ;
2122
2133
2123
- if is_projection_from_ty_closure {
2134
+ if base_ty . is_closure ( ) || base_ty . is_generator ( ) {
2124
2135
Some ( field)
2125
2136
} else {
2126
2137
None
0 commit comments