@@ -1366,7 +1366,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
13661366 ) {
13671367 debug ! ( "check_if_reassignment_to_immutable_state({:?})" , place) ;
13681368 // determine if this path has a non-mut owner (and thus needs checking).
1369- if let Ok ( _ ) = self . is_mutable ( place, LocalMutationIsAllowed :: No ) {
1369+ if let Ok ( .. ) = self . is_mutable ( place, LocalMutationIsAllowed :: No ) {
13701370 return ;
13711371 }
13721372 debug ! (
@@ -1681,24 +1681,23 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
16811681 Reservation ( WriteKind :: MutableBorrow ( BorrowKind :: Mut { .. } ) )
16821682 | Write ( WriteKind :: MutableBorrow ( BorrowKind :: Mut { .. } ) ) => {
16831683 match self . is_mutable ( place, is_local_mutation_allowed) {
1684- Ok ( Place :: Local ( local) )
1685- if is_local_mutation_allowed != LocalMutationIsAllowed :: Yes =>
1686- {
1687- // If the local may be initialized, and it is now currently being
1688- // mutated, then it is justified to be annotated with the `mut` keyword,
1689- // since the mutation may be a possible reassignment.
1690- let mpi = self . move_data . rev_lookup . find_local ( * local ) ;
1691- if flow_state . inits . contains ( & mpi ) {
1692- self . used_mut . insert ( * local ) ;
1684+ Ok ( ( Place :: Local ( local) , mut_allowed ) ) => {
1685+ if mut_allowed != LocalMutationIsAllowed :: Yes {
1686+ // If the local may be initialized, and it is now currently being
1687+ // mutated, then it is justified to be annotated with the `mut`
1688+ // keyword, since the mutation may be a possible reassignment.
1689+ let mpi = self . move_data . rev_lookup . find_local ( * local ) ;
1690+ if flow_state . inits . contains ( & mpi ) {
1691+ self . used_mut . insert ( * local ) ;
1692+ }
16931693 }
16941694 }
1695- Ok ( Place :: Projection ( ref proj) ) => {
1695+ Ok ( ( Place :: Projection ( ref proj) , _mut_allowed ) ) => {
16961696 if let Some ( field) = self . is_upvar_field_projection ( & proj. base ) {
16971697 self . used_mut_upvars . push ( field) ;
16981698 }
16991699 }
1700- Ok ( Place :: Local ( _) ) |
1701- Ok ( Place :: Static ( ..) ) => { }
1700+ Ok ( ( Place :: Static ( ..) , _mut_allowed) ) => { }
17021701 Err ( place_err) => {
17031702 error_reported = true ;
17041703 let item_msg = self . get_default_err_msg ( place) ;
@@ -1719,24 +1718,23 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
17191718 }
17201719 Reservation ( WriteKind :: Mutate ) | Write ( WriteKind :: Mutate ) => {
17211720 match self . is_mutable ( place, is_local_mutation_allowed) {
1722- Ok ( Place :: Local ( local) )
1723- if is_local_mutation_allowed != LocalMutationIsAllowed :: Yes =>
1724- {
1725- // If the local may be initialized, and it is now currently being
1726- // mutated, then it is justified to be annotated with the `mut` keyword,
1727- // since the mutation may be a possible reassignment.
1728- let mpi = self . move_data . rev_lookup . find_local ( * local ) ;
1729- if flow_state . inits . contains ( & mpi ) {
1730- self . used_mut . insert ( * local ) ;
1721+ Ok ( ( Place :: Local ( local) , mut_allowed ) ) => {
1722+ if mut_allowed != LocalMutationIsAllowed :: Yes {
1723+ // If the local may be initialized, and it is now currently being
1724+ // mutated, then it is justified to be annotated with the `mut`
1725+ // keyword, since the mutation may be a possible reassignment.
1726+ let mpi = self . move_data . rev_lookup . find_local ( * local ) ;
1727+ if flow_state . inits . contains ( & mpi ) {
1728+ self . used_mut . insert ( * local ) ;
1729+ }
17311730 }
17321731 }
1733- Ok ( Place :: Projection ( ref proj) ) => {
1732+ Ok ( ( Place :: Projection ( ref proj) , _mut_allowed ) ) => {
17341733 if let Some ( field) = self . is_upvar_field_projection ( & proj. base ) {
17351734 self . used_mut_upvars . push ( field) ;
17361735 }
17371736 }
1738- Ok ( Place :: Local ( _) ) |
1739- Ok ( Place :: Static ( ..) ) => { }
1737+ Ok ( ( Place :: Static ( ..) , _mut_allowed) ) => { }
17401738 Err ( place_err) => {
17411739 error_reported = true ;
17421740
@@ -1835,25 +1833,28 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18351833 & self ,
18361834 place : & ' d Place < ' tcx > ,
18371835 is_local_mutation_allowed : LocalMutationIsAllowed ,
1838- ) -> Result < & ' d Place < ' tcx > , & ' d Place < ' tcx > > {
1836+ ) -> Result < ( & ' d Place < ' tcx > , LocalMutationIsAllowed ) , & ' d Place < ' tcx > > {
18391837 match * place {
18401838 Place :: Local ( local) => {
18411839 let local = & self . mir . local_decls [ local] ;
18421840 match local. mutability {
18431841 Mutability :: Not => match is_local_mutation_allowed {
1844- LocalMutationIsAllowed :: Yes | LocalMutationIsAllowed :: ExceptUpvars => {
1845- Ok ( place)
1842+ LocalMutationIsAllowed :: Yes => {
1843+ Ok ( ( place, LocalMutationIsAllowed :: Yes ) )
1844+ }
1845+ LocalMutationIsAllowed :: ExceptUpvars => {
1846+ Ok ( ( place, LocalMutationIsAllowed :: ExceptUpvars ) )
18461847 }
18471848 LocalMutationIsAllowed :: No => Err ( place) ,
18481849 } ,
1849- Mutability :: Mut => Ok ( place) ,
1850+ Mutability :: Mut => Ok ( ( place, is_local_mutation_allowed ) ) ,
18501851 }
18511852 }
18521853 Place :: Static ( ref static_) =>
18531854 if self . tcx . is_static ( static_. def_id ) != Some ( hir:: Mutability :: MutMutable ) {
18541855 Err ( place)
18551856 } else {
1856- Ok ( place)
1857+ Ok ( ( place, is_local_mutation_allowed ) )
18571858 } ,
18581859 Place :: Projection ( ref proj) => {
18591860 match proj. elem {
@@ -1891,7 +1892,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18911892 hir:: MutImmutable => return Err ( place) ,
18921893 // `*mut` raw pointers are always mutable, regardless of context
18931894 // The users have to check by themselve.
1894- hir:: MutMutable => return Ok ( place) ,
1895+ hir:: MutMutable => return Ok ( ( place, is_local_mutation_allowed ) ) ,
18951896 }
18961897 }
18971898 // `Box<T>` owns its content, so mutable if its location is mutable
0 commit comments