@@ -1398,9 +1398,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1398
1398
) {
1399
1399
debug ! ( "check_if_reassignment_to_immutable_state({:?})" , place) ;
1400
1400
// determine if this path has a non-mut owner (and thus needs checking).
1401
- if let Ok ( ..) = self . is_mutable ( place, LocalMutationIsAllowed :: No ) {
1402
- return ;
1403
- }
1401
+ let err_place = match self . is_mutable ( place, LocalMutationIsAllowed :: No ) {
1402
+ Ok ( ..) => return ,
1403
+ Err ( place) => place,
1404
+ } ;
1404
1405
debug ! (
1405
1406
"check_if_reassignment_to_immutable_state({:?}) - is an imm local" ,
1406
1407
place
@@ -1410,7 +1411,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1410
1411
let init = self . move_data . inits [ i] ;
1411
1412
let init_place = & self . move_data . move_paths [ init. path ] . place ;
1412
1413
if places_conflict ( self . tcx , self . mir , & init_place, place, Deep ) {
1413
- self . report_illegal_reassignment ( context, ( place, span) , init. span ) ;
1414
+ self . report_illegal_reassignment ( context, ( place, span) , init. span , err_place ) ;
1414
1415
break ;
1415
1416
}
1416
1417
}
@@ -1784,7 +1785,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1784
1785
match the_place_err {
1785
1786
// We want to suggest users use `let mut` for local (user
1786
1787
// variable) mutations...
1787
- Place :: Local ( local) if local_can_be_made_mutable ( self . mir , * local) => {
1788
+ Place :: Local ( local) if self . mir . local_decls [ * local] . can_be_made_mutable ( ) => {
1788
1789
// ... but it doesn't make sense to suggest it on
1789
1790
// variables that are `ref x`, `ref mut x`, `&self`,
1790
1791
// or `&mut self` (such variables are simply not
@@ -1819,7 +1820,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1819
1820
// arbitrary base for the projection?
1820
1821
Place :: Projection ( box Projection { base : Place :: Local ( local) ,
1821
1822
elem : ProjectionElem :: Deref } )
1822
- if local_is_nonref_binding ( self . mir , * local) =>
1823
+ if self . mir . local_decls [ * local] . is_nonref_binding ( ) =>
1823
1824
{
1824
1825
let ( err_help_span, suggested_code) =
1825
1826
find_place_to_suggest_ampmut ( self . tcx , self . mir , * local) ;
@@ -1846,43 +1847,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1846
1847
err. emit ( ) ;
1847
1848
return true ;
1848
1849
1849
- // Returns true if local is a binding that can itself be made
1850
- // mutable via the addition of the `mut` keyword, namely
1851
- // something like:
1852
- // - `fn foo(x: Type) { ... }`,
1853
- // - `let x = ...`,
1854
- // - or `match ... { C(x) => ... }`
1855
- fn local_can_be_made_mutable ( mir : & Mir , local : mir:: Local ) -> bool
1856
- {
1857
- let local = & mir. local_decls [ local] ;
1858
- match local. is_user_variable {
1859
- Some ( ClearCrossCrate :: Set ( mir:: BindingForm :: Var ( mir:: VarBindingForm {
1860
- binding_mode : ty:: BindingMode :: BindByValue ( _) ,
1861
- opt_ty_info : _,
1862
- } ) ) ) => true ,
1863
-
1864
- _ => false ,
1865
- }
1866
- }
1867
-
1868
- // Returns true if local is definitely not a `ref ident` or
1869
- // `ref mut ident` binding. (Such bindings cannot be made into
1870
- // mutable bindings.)
1871
- fn local_is_nonref_binding ( mir : & Mir , local : mir:: Local ) -> bool
1872
- {
1873
- let local = & mir. local_decls [ local] ;
1874
- match local. is_user_variable {
1875
- Some ( ClearCrossCrate :: Set ( mir:: BindingForm :: Var ( mir:: VarBindingForm {
1876
- binding_mode : ty:: BindingMode :: BindByValue ( _) ,
1877
- opt_ty_info : _,
1878
- } ) ) ) => true ,
1879
-
1880
- Some ( ClearCrossCrate :: Set ( mir:: BindingForm :: ImplicitSelf ) ) => true ,
1881
-
1882
- _ => false ,
1883
- }
1884
- }
1885
-
1886
1850
// Returns the span to highlight and the associated text to
1887
1851
// present when suggesting that the user use an `&mut`.
1888
1852
//
0 commit comments