@@ -182,9 +182,6 @@ fn do_mir_borrowck<'tcx>(
182182    let  location_table = PoloniusLocationTable :: new ( body) ; 
183183
184184    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 ) ) ) ; 
188185
189186    let  flow_inits = MaybeInitializedPlaces :: new ( tcx,  body,  & move_data) 
190187        . iterate_to_fixpoint ( tcx,  body,  Some ( "borrowck" ) ) 
@@ -242,10 +239,14 @@ fn do_mir_borrowck<'tcx>(
242239        false 
243240    } ; 
244241
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 { 
246245        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 ) ; 
249250        let  mut  promoted_mbcx = MirBorrowckCtxt  { 
250251            infcx :  & infcx, 
251252            body :  promoted_body, 
@@ -270,9 +271,6 @@ fn do_mir_borrowck<'tcx>(
270271            move_errors :  Vec :: new ( ) , 
271272            diags_buffer, 
272273        } ; 
273-         MoveVisitor  {  ctxt :  & mut  promoted_mbcx } . visit_body ( promoted_body) ; 
274-         promoted_mbcx. report_move_errors ( ) ; 
275- 
276274        struct  MoveVisitor < ' a ,  ' b ,  ' infcx ,  ' tcx >  { 
277275            ctxt :  & ' a  mut  MirBorrowckCtxt < ' b ,  ' infcx ,  ' tcx > , 
278276        } 
@@ -284,6 +282,8 @@ fn do_mir_borrowck<'tcx>(
284282                } 
285283            } 
286284        } 
285+         MoveVisitor  {  ctxt :  & mut  promoted_mbcx } . visit_body ( promoted_body) ; 
286+         promoted_mbcx. report_move_errors ( ) ; 
287287    } 
288288
289289    let  mut  mbcx = MirBorrowckCtxt  { 
0 commit comments