@@ -1366,7 +1366,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1366
1366
) {
1367
1367
debug ! ( "check_if_reassignment_to_immutable_state({:?})" , place) ;
1368
1368
// 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 ) {
1370
1370
return ;
1371
1371
}
1372
1372
debug ! (
@@ -1681,24 +1681,23 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1681
1681
Reservation ( WriteKind :: MutableBorrow ( BorrowKind :: Mut { .. } ) )
1682
1682
| Write ( WriteKind :: MutableBorrow ( BorrowKind :: Mut { .. } ) ) => {
1683
1683
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
+ }
1693
1693
}
1694
1694
}
1695
- Ok ( Place :: Projection ( ref proj) ) => {
1695
+ Ok ( ( Place :: Projection ( ref proj) , _mut_allowed ) ) => {
1696
1696
if let Some ( field) = self . is_upvar_field_projection ( & proj. base ) {
1697
1697
self . used_mut_upvars . push ( field) ;
1698
1698
}
1699
1699
}
1700
- Ok ( Place :: Local ( _) ) |
1701
- Ok ( Place :: Static ( ..) ) => { }
1700
+ Ok ( ( Place :: Static ( ..) , _mut_allowed) ) => { }
1702
1701
Err ( place_err) => {
1703
1702
error_reported = true ;
1704
1703
let item_msg = self . get_default_err_msg ( place) ;
@@ -1719,24 +1718,23 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1719
1718
}
1720
1719
Reservation ( WriteKind :: Mutate ) | Write ( WriteKind :: Mutate ) => {
1721
1720
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
+ }
1731
1730
}
1732
1731
}
1733
- Ok ( Place :: Projection ( ref proj) ) => {
1732
+ Ok ( ( Place :: Projection ( ref proj) , _mut_allowed ) ) => {
1734
1733
if let Some ( field) = self . is_upvar_field_projection ( & proj. base ) {
1735
1734
self . used_mut_upvars . push ( field) ;
1736
1735
}
1737
1736
}
1738
- Ok ( Place :: Local ( _) ) |
1739
- Ok ( Place :: Static ( ..) ) => { }
1737
+ Ok ( ( Place :: Static ( ..) , _mut_allowed) ) => { }
1740
1738
Err ( place_err) => {
1741
1739
error_reported = true ;
1742
1740
@@ -1835,25 +1833,28 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1835
1833
& self ,
1836
1834
place : & ' d Place < ' tcx > ,
1837
1835
is_local_mutation_allowed : LocalMutationIsAllowed ,
1838
- ) -> Result < & ' d Place < ' tcx > , & ' d Place < ' tcx > > {
1836
+ ) -> Result < ( & ' d Place < ' tcx > , LocalMutationIsAllowed ) , & ' d Place < ' tcx > > {
1839
1837
match * place {
1840
1838
Place :: Local ( local) => {
1841
1839
let local = & self . mir . local_decls [ local] ;
1842
1840
match local. mutability {
1843
1841
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 ) )
1846
1847
}
1847
1848
LocalMutationIsAllowed :: No => Err ( place) ,
1848
1849
} ,
1849
- Mutability :: Mut => Ok ( place) ,
1850
+ Mutability :: Mut => Ok ( ( place, is_local_mutation_allowed ) ) ,
1850
1851
}
1851
1852
}
1852
1853
Place :: Static ( ref static_) =>
1853
1854
if self . tcx . is_static ( static_. def_id ) != Some ( hir:: Mutability :: MutMutable ) {
1854
1855
Err ( place)
1855
1856
} else {
1856
- Ok ( place)
1857
+ Ok ( ( place, is_local_mutation_allowed ) )
1857
1858
} ,
1858
1859
Place :: Projection ( ref proj) => {
1859
1860
match proj. elem {
@@ -1891,7 +1892,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1891
1892
hir:: MutImmutable => return Err ( place) ,
1892
1893
// `*mut` raw pointers are always mutable, regardless of context
1893
1894
// The users have to check by themselve.
1894
- hir:: MutMutable => return Ok ( place) ,
1895
+ hir:: MutMutable => return Ok ( ( place, is_local_mutation_allowed ) ) ,
1895
1896
}
1896
1897
}
1897
1898
// `Box<T>` owns its content, so mutable if its location is mutable
0 commit comments