@@ -1398,9 +1398,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
13981398 ) {
13991399 debug ! ( "check_if_reassignment_to_immutable_state({:?})" , place) ;
14001400 // 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+ } ;
14041405 debug ! (
14051406 "check_if_reassignment_to_immutable_state({:?}) - is an imm local" ,
14061407 place
@@ -1410,7 +1411,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
14101411 let init = self . move_data . inits [ i] ;
14111412 let init_place = & self . move_data . move_paths [ init. path ] . place ;
14121413 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 ) ;
14141415 break ;
14151416 }
14161417 }
@@ -1784,7 +1785,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
17841785 match the_place_err {
17851786 // We want to suggest users use `let mut` for local (user
17861787 // 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 ( ) => {
17881789 // ... but it doesn't make sense to suggest it on
17891790 // variables that are `ref x`, `ref mut x`, `&self`,
17901791 // or `&mut self` (such variables are simply not
@@ -1819,7 +1820,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18191820 // arbitrary base for the projection?
18201821 Place :: Projection ( box Projection { base : Place :: Local ( local) ,
18211822 elem : ProjectionElem :: Deref } )
1822- if local_is_nonref_binding ( self . mir , * local) =>
1823+ if self . mir . local_decls [ * local] . is_nonref_binding ( ) =>
18231824 {
18241825 let ( err_help_span, suggested_code) =
18251826 find_place_to_suggest_ampmut ( self . tcx , self . mir , * local) ;
@@ -1846,43 +1847,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18461847 err. emit ( ) ;
18471848 return true ;
18481849
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-
18861850 // Returns the span to highlight and the associated text to
18871851 // present when suggesting that the user use an `&mut`.
18881852 //
0 commit comments