]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/transform/check_consts/qualifs.rs
Remove PlaceBase enum and make Place base field be local: Local
[rust.git] / src / librustc_mir / transform / check_consts / qualifs.rs
index 746d83b05c6b318f4ea256b2e17d811cf5e5299e..577736f9bd11df64a011adb3f6745890e086d3fc 100644 (file)
@@ -1,9 +1,8 @@
 //! A copy of the `Qualif` trait in `qualify_consts.rs` that is suitable for the new validator.
 
-use rustc::hir::def_id::DefId;
 use rustc::mir::*;
 use rustc::ty::{self, Ty};
-use syntax_pos::DUMMY_SP;
+use rustc_span::DUMMY_SP;
 
 use super::Item as ConstCx;
 
@@ -33,24 +32,21 @@ pub trait Qualif {
     /// of the type.
     fn in_any_value_of_ty(_cx: &ConstCx<'_, 'tcx>, _ty: Ty<'tcx>) -> bool;
 
-    fn in_static(cx: &ConstCx<'_, 'tcx>, def_id: DefId) -> bool {
-        // `mir_const_qualif` does return the qualifs in the final value of a `static`, so we could
-        // use value-based qualification here, but we shouldn't do this without a good reason.
-        Self::in_any_value_of_ty(cx, cx.tcx.type_of(def_id))
-    }
-
     fn in_projection_structurally(
         cx: &ConstCx<'_, 'tcx>,
         per_local: &impl Fn(Local) -> bool,
         place: PlaceRef<'_, 'tcx>,
     ) -> bool {
         if let [proj_base @ .., elem] = place.projection {
-            let base_qualif =
-                Self::in_place(cx, per_local, PlaceRef { base: place.base, projection: proj_base });
+            let base_qualif = Self::in_place(
+                cx,
+                per_local,
+                PlaceRef { local: place.local, projection: proj_base },
+            );
             let qualif = base_qualif
                 && Self::in_any_value_of_ty(
                     cx,
-                    Place::ty_from(place.base, proj_base, *cx.body, cx.tcx)
+                    Place::ty_from(place.local, proj_base, *cx.body, cx.tcx)
                         .projection_ty(cx.tcx, elem)
                         .ty,
                 );
@@ -82,11 +78,8 @@ fn in_place(
         place: PlaceRef<'_, 'tcx>,
     ) -> bool {
         match place {
-            PlaceRef { base: PlaceBase::Local(local), projection: [] } => per_local(*local),
-            PlaceRef { base: PlaceBase::Static(_), projection: [] } => {
-                bug!("qualifying already promoted MIR")
-            }
-            PlaceRef { base: _, projection: [.., _] } => Self::in_projection(cx, per_local, place),
+            PlaceRef { local, projection: [] } => per_local(*local),
+            PlaceRef { local: _, projection: [.., _] } => Self::in_projection(cx, per_local, place),
         }
     }
 
@@ -101,9 +94,17 @@ fn in_operand(
             }
 
             Operand::Constant(ref constant) => {
-                if let Some(static_) = constant.check_static_ptr(cx.tcx) {
-                    Self::in_static(cx, static_)
-                } else if let ty::ConstKind::Unevaluated(def_id, _) = constant.literal.val {
+                if constant.check_static_ptr(cx.tcx).is_some() {
+                    // `mir_const_qualif` does return the qualifs in the final value of a `static`,
+                    // so we could use value-based qualification here, but we shouldn't do this
+                    // without a good reason.
+                    //
+                    // Note: this uses `constant.literal.ty` which is a reference or pointer to the
+                    // type of the actual `static` item.
+                    Self::in_any_value_of_ty(cx, constant.literal.ty)
+                } else if let ty::ConstKind::Unevaluated(def_id, _, promoted) = constant.literal.val
+                {
+                    assert!(promoted.is_none());
                     // Don't peek inside trait associated constants.
                     if cx.tcx.trait_of_item(def_id).is_some() {
                         Self::in_any_value_of_ty(cx, constant.literal.ty)
@@ -148,12 +149,12 @@ fn in_rvalue_structurally(
             Rvalue::Ref(_, _, ref place) | Rvalue::AddressOf(_, ref place) => {
                 // Special-case reborrows to be more like a copy of the reference.
                 if let [proj_base @ .., ProjectionElem::Deref] = place.projection.as_ref() {
-                    let base_ty = Place::ty_from(&place.base, proj_base, *cx.body, cx.tcx).ty;
+                    let base_ty = Place::ty_from(&place.local, proj_base, *cx.body, cx.tcx).ty;
                     if let ty::Ref(..) = base_ty.kind {
                         return Self::in_place(
                             cx,
                             per_local,
-                            PlaceRef { base: &place.base, projection: proj_base },
+                            PlaceRef { local: &place.local, projection: proj_base },
                         );
                     }
                 }