@@ -1264,7 +1264,12 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
12641264 if let & Place :: Local ( local) = place_span. 0 {
12651265 if let Mutability :: Not = self . mir . local_decls [ local] . mutability {
12661266 // check for reassignments to immutable local variables
1267- self . check_if_reassignment_to_immutable_state ( context, place_span, flow_state) ;
1267+ self . check_if_reassignment_to_immutable_state (
1268+ context,
1269+ local,
1270+ place_span,
1271+ flow_state,
1272+ ) ;
12681273 return ;
12691274 }
12701275 }
@@ -1575,27 +1580,20 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
15751580 fn check_if_reassignment_to_immutable_state (
15761581 & mut self ,
15771582 context : Context ,
1578- ( place, span) : ( & Place < ' tcx > , Span ) ,
1583+ local : Local ,
1584+ place_span : ( & Place < ' tcx > , Span ) ,
15791585 flow_state : & Flows < ' cx , ' gcx , ' tcx > ,
15801586 ) {
1581- debug ! ( "check_if_reassignment_to_immutable_state({:?})" , place) ;
1582- // determine if this path has a non-mut owner (and thus needs checking).
1583- let err_place = match self . is_mutable ( place, LocalMutationIsAllowed :: No ) {
1584- Ok ( ..) => return ,
1585- Err ( place) => place,
1586- } ;
1587- debug ! (
1588- "check_if_reassignment_to_immutable_state({:?}) - is an imm local" ,
1589- place
1590- ) ;
1591-
1592- for i in flow_state. ever_inits . iter_incoming ( ) {
1593- let init = self . move_data . inits [ i] ;
1594- let init_place = & self . move_data . move_paths [ init. path ] . place ;
1595- if places_conflict:: places_conflict ( self . tcx , self . mir , & init_place, place, Deep ) {
1596- self . report_illegal_reassignment ( context, ( place, span) , init. span , err_place) ;
1597- break ;
1598- }
1587+ debug ! ( "check_if_reassignment_to_immutable_state({:?})" , local) ;
1588+
1589+ // Check if any of the initializiations of `local` have happened yet:
1590+ let mpi = self . move_data . rev_lookup . find_local ( local) ;
1591+ let init_indices = & self . move_data . init_path_map [ mpi] ;
1592+ let first_init_index = init_indices. iter ( ) . find ( |ii| flow_state. ever_inits . contains ( ii) ) ;
1593+ if let Some ( & init_index) = first_init_index {
1594+ // And, if so, report an error.
1595+ let init = & self . move_data . inits [ init_index] ;
1596+ self . report_illegal_reassignment ( context, place_span, init. span , place_span. 0 ) ;
15991597 }
16001598 }
16011599
0 commit comments