@@ -183,9 +183,6 @@ fn do_mir_borrowck<'tcx>(
183183 let location_table = LocationTable :: new ( body) ;
184184
185185 let move_data = MoveData :: gather_moves ( body, tcx, |_| true ) ;
186- let promoted_move_data = promoted
187- . iter_enumerated ( )
188- . map ( |( idx, body) | ( idx, MoveData :: gather_moves ( body, tcx, |_| true ) ) ) ;
189186
190187 let flow_inits = MaybeInitializedPlaces :: new ( tcx, body, & move_data)
191188 . iterate_to_fixpoint ( tcx, body, Some ( "borrowck" ) )
@@ -235,10 +232,14 @@ fn do_mir_borrowck<'tcx>(
235232 false
236233 } ;
237234
238- for ( idx, move_data) in promoted_move_data {
235+ // While promoteds should mostly be correct by construction, we need to check them for
236+ // invalid moves to detect moving out of arrays:`struct S; fn main() { &([S][0]); }`.
237+ for promoted_body in & promoted {
239238 use rustc_middle:: mir:: visit:: Visitor ;
240-
241- let promoted_body = & promoted[ idx] ;
239+ // This assumes that we won't use some of the fields of the `promoted_mbcx`
240+ // when detecting and reporting move errors. While it would be nice to move
241+ // this check out of `MirBorrowckCtxt`, actually doing so is far from trivial.
242+ let move_data = MoveData :: gather_moves ( promoted_body, tcx, |_| true ) ;
242243 let mut promoted_mbcx = MirBorrowckCtxt {
243244 infcx : & infcx,
244245 body : promoted_body,
@@ -262,9 +263,6 @@ fn do_mir_borrowck<'tcx>(
262263 move_errors : Vec :: new ( ) ,
263264 diags,
264265 } ;
265- MoveVisitor { ctxt : & mut promoted_mbcx } . visit_body ( promoted_body) ;
266- promoted_mbcx. report_move_errors ( ) ;
267-
268266 struct MoveVisitor < ' a , ' b , ' infcx , ' tcx > {
269267 ctxt : & ' a mut MirBorrowckCtxt < ' b , ' infcx , ' tcx > ,
270268 }
@@ -276,6 +274,8 @@ fn do_mir_borrowck<'tcx>(
276274 }
277275 }
278276 }
277+ MoveVisitor { ctxt : & mut promoted_mbcx } . visit_body ( promoted_body) ;
278+ promoted_mbcx. report_move_errors ( ) ;
279279 }
280280
281281 let mut mbcx = MirBorrowckCtxt {
0 commit comments