]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/borrow_check/mutability_errors.rs
Use slice patterns to match projection base
[rust.git] / src / librustc_mir / borrow_check / mutability_errors.rs
index dbc1d1700933f5ed52026dd4d291dd1f5b295263..12dc2cd1f91c36da67cf00aae88ba0d3b3e583e6 100644 (file)
@@ -65,10 +65,8 @@ pub(super) fn report_mutability_error(
 
             PlaceRef {
                 base: _,
-                projection: [.., ProjectionElem::Field(upvar_index, _)],
+                projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)],
             } => {
-                let proj_base = &the_place_err.projection[..the_place_err.projection.len() - 1];
-
                 debug_assert!(is_closure_or_generator(
                     Place::ty_from(&the_place_err.base, proj_base, self.body, self.infcx.tcx).ty
                 ));
@@ -329,10 +327,8 @@ pub(super) fn report_mutability_error(
             // Also suggest adding mut for upvars
             PlaceRef {
                 base,
-                projection: [.., ProjectionElem::Field(upvar_index, _)],
+                projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)],
             } => {
-                let proj_base = &the_place_err.projection[..the_place_err.projection.len() - 1];
-
                 debug_assert!(is_closure_or_generator(
                     Place::ty_from(base, proj_base, self.body, self.infcx.tcx).ty
                 ));