about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_mir/borrow_check/conflict_errors.rs5
-rw-r--r--src/librustc_mir/borrow_check/mod.rs7
-rw-r--r--src/librustc_mir/borrow_check/mutability_errors.rs9
-rw-r--r--src/librustc_mir/build/expr/as_rvalue.rs16
-rw-r--r--src/librustc_mir/transform/instcombine.rs22
5 files changed, 24 insertions, 35 deletions
diff --git a/src/librustc_mir/borrow_check/conflict_errors.rs b/src/librustc_mir/borrow_check/conflict_errors.rs
index 413f7e2e406..c901eb29054 100644
--- a/src/librustc_mir/borrow_check/conflict_errors.rs
+++ b/src/librustc_mir/borrow_check/conflict_errors.rs
@@ -1520,10 +1520,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
             [] => {
                 StorageDeadOrDrop::LocalStorageDead
             }
-            [.., elem] => {
-                // FIXME(spastorino) revisit when we get rid of Box
-                let base = &place.projection[..place.projection.len() - 1];
-
+            [base @ .., elem] => {
                 // FIXME(spastorino) make this iterate
                 let base_access = self.classify_drop_access_kind(PlaceRef {
                     base: place.base,
diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs
index 3b10d8f1966..5ef70461296 100644
--- a/src/librustc_mir/borrow_check/mod.rs
+++ b/src/librustc_mir/borrow_check/mod.rs
@@ -2324,14 +2324,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
         let mut place_projection = place_ref.projection;
         let mut by_ref = false;
 
-        if let [.., ProjectionElem::Deref] = place_projection {
-            place_projection = &place_projection[..place_projection.len() - 1];
+        if let [proj_base @ .., ProjectionElem::Deref] = place_projection {
+            place_projection = proj_base;
             by_ref = true;
         }
 
         match place_projection {
-            [.., ProjectionElem::Field(field, _ty)] => {
-                let base = &place_projection[..place_projection.len() - 1];
+            [base @ .., ProjectionElem::Field(field, _ty)] => {
                 let tcx = self.infcx.tcx;
                 let base_ty = Place::ty_from(place_ref.base, base, self.body, tcx).ty;
 
diff --git a/src/librustc_mir/borrow_check/mutability_errors.rs b/src/librustc_mir/borrow_check/mutability_errors.rs
index 12dc2cd1f91..9b9dfc30233 100644
--- a/src/librustc_mir/borrow_check/mutability_errors.rs
+++ b/src/librustc_mir/borrow_check/mutability_errors.rs
@@ -82,11 +82,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
 
             PlaceRef {
                 base: _,
-                projection: [.., ProjectionElem::Deref],
+                projection: [base @ .., ProjectionElem::Deref],
             } => {
-                // FIXME(spastorino) once released use box [base @ .., ProjectionElem::Deref]
-                let base = &the_place_err.projection[..the_place_err.projection.len() - 1];
-
                 if the_place_err.base == &PlaceBase::Local(Local::new(1)) &&
                     base.is_empty() &&
                     !self.upvars.is_empty() {
@@ -243,14 +240,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
             // after the field access).
             PlaceRef {
                 base,
-                projection: [..,
+                projection: [base_proj @ ..,
                              ProjectionElem::Deref,
                              ProjectionElem::Field(field, _),
                              ProjectionElem::Deref,
                 ],
             } => {
-                let base_proj = &the_place_err.projection[..the_place_err.projection.len() - 3];
-
                 err.span_label(span, format!("cannot {ACT}", ACT = act));
 
                 if let Some((span, message)) = annotate_struct_field(
diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs
index 1371bc5aee8..6692984524f 100644
--- a/src/librustc_mir/build/expr/as_rvalue.rs
+++ b/src/librustc_mir/build/expr/as_rvalue.rs
@@ -514,20 +514,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
             }
             Place {
                 ref base,
-                projection: box [.., ProjectionElem::Field(upvar_index, _)],
+                projection: box [ref base_proj @ .., ProjectionElem::Field(upvar_index, _)],
             }
             | Place {
                 ref base,
-                projection: box [.., ProjectionElem::Field(upvar_index, _), ProjectionElem::Deref],
+                projection: box [
+                    ref base_proj @ ..,
+                    ProjectionElem::Field(upvar_index, _),
+                    ProjectionElem::Deref
+                ],
             } => {
-                let base_proj = if let ProjectionElem::Deref =
-                    arg_place.projection[arg_place.projection.len() - 1]
-                {
-                    &arg_place.projection[..arg_place.projection.len() - 2]
-                } else {
-                    &arg_place.projection[..arg_place.projection.len() - 1]
-                };
-
                 let place = PlaceRef {
                     base,
                     projection: base_proj,
diff --git a/src/librustc_mir/transform/instcombine.rs b/src/librustc_mir/transform/instcombine.rs
index da91a8daca3..0e04e63af45 100644
--- a/src/librustc_mir/transform/instcombine.rs
+++ b/src/librustc_mir/transform/instcombine.rs
@@ -45,16 +45,18 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> {
                     ref mut base,
                     projection: ref mut projection @ box [.., _],
                 }) => {
-                    let [proj_l @ .., proj_r] = projection;
-
-                    let place = Place {
-                        // Replace with dummy
-                        base: mem::replace(base, PlaceBase::Local(Local::new(0))),
-                        projection: proj_l.to_vec().into_boxed_slice(),
-                    };
-                    *projection = proj_r.to_vec().into_boxed_slice();
-
-                    place
+                    if let box [proj_l @ .., proj_r] = projection {
+                        let place = Place {
+                            // Replace with dummy
+                            base: mem::replace(base, PlaceBase::Local(Local::new(0))),
+                            projection: proj_l.to_vec().into_boxed_slice(),
+                        };
+                        *projection = vec![proj_r.clone()].into_boxed_slice();
+
+                        place
+                    } else {
+                        unreachable!();
+                    }
                 }
                 _ => bug!("Detected `&*` but didn't find `&*`!"),
             };