@@ -182,9 +182,6 @@ fn do_mir_borrowck<'tcx>(
182
182
let location_table = PoloniusLocationTable :: new ( body) ;
183
183
184
184
let move_data = MoveData :: gather_moves ( body, tcx, |_| true ) ;
185
- let promoted_move_data = promoted
186
- . iter_enumerated ( )
187
- . map ( |( idx, body) | ( idx, MoveData :: gather_moves ( body, tcx, |_| true ) ) ) ;
188
185
189
186
let flow_inits = MaybeInitializedPlaces :: new ( tcx, body, & move_data)
190
187
. iterate_to_fixpoint ( tcx, body, Some ( "borrowck" ) )
@@ -242,10 +239,14 @@ fn do_mir_borrowck<'tcx>(
242
239
false
243
240
} ;
244
241
245
- for ( idx, move_data) in promoted_move_data {
242
+ // While promoteds should mostly be correct by construction, we need to check them for
243
+ // invalid moves to detect moving out of arrays:`struct S; fn main() { &([S][0]); }`.
244
+ for promoted_body in & promoted {
246
245
use rustc_middle:: mir:: visit:: Visitor ;
247
-
248
- let promoted_body = & promoted[ idx] ;
246
+ // This assumes that we won't use some of the fields of the `promoted_mbcx`
247
+ // when detecting and reporting move errors. While it would be nice to move
248
+ // this check out of `MirBorrowckCtxt`, actually doing so is far from trivial.
249
+ let move_data = MoveData :: gather_moves ( promoted_body, tcx, |_| true ) ;
249
250
let mut promoted_mbcx = MirBorrowckCtxt {
250
251
infcx : & infcx,
251
252
body : promoted_body,
@@ -270,9 +271,6 @@ fn do_mir_borrowck<'tcx>(
270
271
move_errors : Vec :: new ( ) ,
271
272
diags_buffer,
272
273
} ;
273
- MoveVisitor { ctxt : & mut promoted_mbcx } . visit_body ( promoted_body) ;
274
- promoted_mbcx. report_move_errors ( ) ;
275
-
276
274
struct MoveVisitor < ' a , ' b , ' infcx , ' tcx > {
277
275
ctxt : & ' a mut MirBorrowckCtxt < ' b , ' infcx , ' tcx > ,
278
276
}
@@ -284,6 +282,8 @@ fn do_mir_borrowck<'tcx>(
284
282
}
285
283
}
286
284
}
285
+ MoveVisitor { ctxt : & mut promoted_mbcx } . visit_body ( promoted_body) ;
286
+ promoted_mbcx. report_move_errors ( ) ;
287
287
}
288
288
289
289
let mut mbcx = MirBorrowckCtxt {
0 commit comments