@@ -36,9 +36,8 @@ use std::collections::BTreeMap;
36
36
37
37
use syntax_pos:: Span ;
38
38
39
- use dataflow:: indexes:: BorrowIndex ;
40
- use dataflow:: move_paths:: { HasMoveData , LookupResult , MoveData , MoveError , MovePathIndex } ;
41
- use dataflow:: move_paths:: indexes:: MoveOutIndex ;
39
+ use dataflow:: indexes:: { BorrowIndex , InitIndex , MoveOutIndex , MovePathIndex } ;
40
+ use dataflow:: move_paths:: { HasMoveData , LookupResult , MoveData , MoveError } ;
42
41
use dataflow:: Borrows ;
43
42
use dataflow:: DataflowResultsConsumer ;
44
43
use dataflow:: FlowAtLocation ;
@@ -1442,10 +1441,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1442
1441
debug ! ( "check_if_reassignment_to_immutable_state({:?})" , local) ;
1443
1442
1444
1443
// Check if any of the initializiations of `local` have happened yet:
1445
- let mpi = self . move_data . rev_lookup . find_local ( local) ;
1446
- let init_indices = & self . move_data . init_path_map [ mpi] ;
1447
- let first_init_index = init_indices. iter ( ) . find ( |& ii| flow_state. ever_inits . contains ( * ii) ) ;
1448
- if let Some ( & init_index) = first_init_index {
1444
+ if let Some ( init_index) = self . is_local_ever_initialized ( local, flow_state) {
1449
1445
// And, if so, report an error.
1450
1446
let init = & self . move_data . inits [ init_index] ;
1451
1447
let span = init. span ( & self . mir ) ;
@@ -1889,6 +1885,21 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1889
1885
return true ;
1890
1886
}
1891
1887
1888
+ fn is_local_ever_initialized ( & self ,
1889
+ local : Local ,
1890
+ flow_state : & Flows < ' cx , ' gcx , ' tcx > )
1891
+ -> Option < InitIndex >
1892
+ {
1893
+ let mpi = self . move_data . rev_lookup . find_local ( local) ;
1894
+ let ii = & self . move_data . init_path_map [ mpi] ;
1895
+ for & index in ii {
1896
+ if flow_state. ever_inits . contains ( index) {
1897
+ return Some ( index) ;
1898
+ }
1899
+ }
1900
+ return None ;
1901
+ }
1902
+
1892
1903
/// Adds the place into the used mutable variables set
1893
1904
fn add_used_mut < ' d > (
1894
1905
& mut self ,
@@ -1900,18 +1911,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1900
1911
place : Place :: Local ( local) ,
1901
1912
is_local_mutation_allowed,
1902
1913
} => {
1903
- if is_local_mutation_allowed != LocalMutationIsAllowed :: Yes {
1904
- // If the local may be initialized, and it is now currently being
1905
- // mutated, then it is justified to be annotated with the `mut`
1906
- // keyword, since the mutation may be a possible reassignment.
1907
- let mpi = self . move_data . rev_lookup . find_local ( * local) ;
1908
- let ii = & self . move_data . init_path_map [ mpi] ;
1909
- for & index in ii {
1910
- if flow_state. ever_inits . contains ( index) {
1911
- self . used_mut . insert ( * local) ;
1912
- break ;
1913
- }
1914
- }
1914
+ // If the local may have been initialized, and it is now currently being
1915
+ // mutated, then it is justified to be annotated with the `mut`
1916
+ // keyword, since the mutation may be a possible reassignment.
1917
+ if is_local_mutation_allowed != LocalMutationIsAllowed :: Yes &&
1918
+ self . is_local_ever_initialized ( * local, flow_state) . is_some ( )
1919
+ {
1920
+ self . used_mut . insert ( * local) ;
1915
1921
}
1916
1922
}
1917
1923
RootPlace {
0 commit comments