]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/build/expr/as_place.rs
Rollup merge of #63203 - spastorino:is-mutable-use-place-ref, r=oli-obk
[rust.git] / src / librustc_mir / build / expr / as_place.rs
index 51808ef7ebdeedb5da0cfddb3dce090dc89ac026..7005f274e0e7def29f39b88d373595e4b1751c67 100644 (file)
@@ -4,7 +4,7 @@
 use crate::build::ForGuard::{OutsideGuard, RefWithinGuard};
 use crate::build::{BlockAnd, BlockAndExtension, Builder};
 use crate::hair::*;
-use rustc::mir::interpret::InterpError::BoundsCheck;
+use rustc::mir::interpret::{PanicInfo::BoundsCheck};
 use rustc::mir::*;
 use rustc::ty::{CanonicalUserTypeAnnotation, Variance};
 
@@ -73,13 +73,15 @@ fn expr_as_place(
                 let (usize_ty, bool_ty) = (this.hir.usize_ty(), this.hir.bool_ty());
 
                 let slice = unpack!(block = this.as_place(block, lhs));
-                // region_scope=None so place indexes live forever. They are scalars so they
-                // do not need storage annotations, and they are often copied between
-                // places.
                 // Making this a *fresh* temporary also means we do not have to worry about
                 // the index changing later: Nothing will ever change this temporary.
                 // The "retagging" transformation (for Stacked Borrows) relies on this.
-                let idx = unpack!(block = this.as_temp(block, None, index, Mutability::Mut));
+                let idx = unpack!(block = this.as_temp(
+                    block,
+                    expr.temp_lifetime,
+                    index,
+                    Mutability::Not,
+                ));
 
                 // bounds check:
                 let (len, lt) = (
@@ -98,33 +100,36 @@ fn expr_as_place(
                     &lt,
                     Rvalue::BinaryOp(
                         BinOp::Lt,
-                        Operand::Copy(Place::Base(PlaceBase::Local(idx))),
+                        Operand::Copy(Place::from(idx)),
                         Operand::Copy(len.clone()),
                     ),
                 );
 
                 let msg = BoundsCheck {
                     len: Operand::Move(len),
-                    index: Operand::Copy(Place::Base(PlaceBase::Local(idx))),
+                    index: Operand::Copy(Place::from(idx)),
                 };
                 let success = this.assert(block, Operand::Move(lt), true, msg, expr_span);
                 success.and(slice.index(idx))
             }
-            ExprKind::SelfRef => block.and(Place::Base(PlaceBase::Local(Local::new(1)))),
+            ExprKind::SelfRef => block.and(Place::from(Local::new(1))),
             ExprKind::VarRef { id } => {
                 let place = if this.is_bound_var_in_guard(id) {
                     let index = this.var_local_id(id, RefWithinGuard);
-                    Place::Base(PlaceBase::Local(index)).deref()
+                    Place::from(index).deref()
                 } else {
                     let index = this.var_local_id(id, OutsideGuard);
-                    Place::Base(PlaceBase::Local(index))
+                    Place::from(index)
                 };
                 block.and(place)
             }
-            ExprKind::StaticRef { id } => block.and(Place::Base(PlaceBase::Static(Box::new(Static {
-                ty: expr.ty,
-                kind: StaticKind::Static(id),
-            })))),
+            ExprKind::StaticRef { id } => block.and(Place {
+                base: PlaceBase::Static(Box::new(Static {
+                    ty: expr.ty,
+                    kind: StaticKind::Static(id),
+                })),
+                projection: None,
+            }),
 
             ExprKind::PlaceTypeAscription { source, user_ty } => {
                 let place = unpack!(block = this.as_place(block, source));
@@ -168,14 +173,14 @@ fn expr_as_place(
                         Statement {
                             source_info,
                             kind: StatementKind::AscribeUserType(
-                                Place::Base(PlaceBase::Local(temp.clone())),
+                                Place::from(temp.clone()),
                                 Variance::Invariant,
                                 box UserTypeProjection { base: annotation_index, projs: vec![], },
                             ),
                         },
                     );
                 }
-                block.and(Place::Base(PlaceBase::Local(temp)))
+                block.and(Place::from(temp))
             }
 
             ExprKind::Array { .. }
@@ -211,7 +216,7 @@ fn expr_as_place(
                 });
                 let temp =
                     unpack!(block = this.as_temp(block, expr.temp_lifetime, expr, mutability));
-                block.and(Place::Base(PlaceBase::Local(temp)))
+                block.and(Place::from(temp))
             }
         }
     }