@@ -1181,26 +1181,37 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
11811181 // We need to report back the list of mutable upvars that were
11821182 // moved into the closure and subsequently used by the closure,
11831183 // 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+ }
11971205 }
1206+ Operand :: Move ( Place :: Static ( ..) )
1207+ | Operand :: Copy ( Place :: Static ( ..) )
1208+ | Operand :: Constant ( ..) => { }
11981209 }
1199- Operand :: Move ( Place :: Static ( ..) )
1200- | Operand :: Copy ( ..)
1201- | Operand :: Constant ( ..) => { }
12021210 }
12031211 }
1212+ AggregateKind :: Adt ( ..)
1213+ | AggregateKind :: Array ( ..)
1214+ | AggregateKind :: Tuple { .. } => ( ) ,
12041215 }
12051216
12061217 for operand in operands {
@@ -1939,6 +1950,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
19391950 }
19401951 }
19411952 }
1953+ RootPlace {
1954+ place : _,
1955+ is_local_mutation_allowed : LocalMutationIsAllowed :: Yes ,
1956+ } => { }
19421957 RootPlace {
19431958 place : place @ Place :: Projection ( _) ,
19441959 is_local_mutation_allowed : _,
@@ -2114,13 +2129,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
21142129 match * place {
21152130 Place :: Projection ( ref proj) => match proj. elem {
21162131 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 ) ;
21222133
2123- if is_projection_from_ty_closure {
2134+ if base_ty . is_closure ( ) || base_ty . is_generator ( ) {
21242135 Some ( field)
21252136 } else {
21262137 None
0 commit comments