]> git.lizzy.rs Git - rust.git/commitdiff
Remove StaticKind
authorSantiago Pastorino <spastorino@gmail.com>
Wed, 11 Dec 2019 04:53:46 +0000 (01:53 -0300)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Fri, 10 Jan 2020 08:08:24 +0000 (09:08 +0100)
12 files changed:
src/librustc/mir/mod.rs
src/librustc/mir/visit.rs
src/librustc_codegen_ssa/mir/place.rs
src/librustc_mir/borrow_check/diagnostics/mod.rs
src/librustc_mir/borrow_check/mod.rs
src/librustc_mir/borrow_check/places_conflict.rs
src/librustc_mir/borrow_check/type_check/mod.rs
src/librustc_mir/interpret/machine.rs
src/librustc_mir/interpret/place.rs
src/librustc_mir/monomorphize/collector.rs
src/librustc_mir/transform/check_unsafety.rs
src/librustc_mir/transform/promote_consts.rs

index 2a33e91a69f086454ffaa3bd3fc9fc712cb44021..42d24d9f332b404e4662a984156d8b200e0dc3f3 100644 (file)
@@ -1687,7 +1687,6 @@ pub enum PlaceBase<'tcx> {
 )]
 pub struct Static<'tcx> {
     pub ty: Ty<'tcx>,
-    pub kind: StaticKind,
     /// The `DefId` of the item this static was declared in. For promoted values, usually, this is
     /// the same as the `DefId` of the `mir::Body` containing the `Place` this promoted appears in.
     /// However, after inlining, that might no longer be the case as inlined `Place`s are copied
@@ -1695,22 +1694,6 @@ pub struct Static<'tcx> {
     pub def_id: DefId,
 }
 
-#[derive(
-    Clone,
-    Debug,
-    PartialEq,
-    Eq,
-    PartialOrd,
-    Ord,
-    Hash,
-    HashStable,
-    RustcEncodable,
-    RustcDecodable
-)]
-pub enum StaticKind {
-    Static,
-}
-
 #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
 #[derive(RustcEncodable, RustcDecodable, HashStable)]
 pub enum ProjectionElem<V, T> {
@@ -1942,7 +1925,7 @@ impl Debug for PlaceBase<'_> {
     fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
         match *self {
             PlaceBase::Local(id) => write!(fmt, "{:?}", id),
-            PlaceBase::Static(box self::Static { ty, kind: StaticKind::Static, def_id }) => {
+            PlaceBase::Static(box self::Static { ty, def_id }) => {
                 write!(fmt, "({}: {:?})", ty::tls::with(|tcx| tcx.def_path_str(def_id)), ty)
             }
         }
@@ -3046,31 +3029,13 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
 
 impl<'tcx> TypeFoldable<'tcx> for Static<'tcx> {
     fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
-        Static {
-            ty: self.ty.fold_with(folder),
-            kind: self.kind.fold_with(folder),
-            def_id: self.def_id,
-        }
+        Static { ty: self.ty.fold_with(folder), def_id: self.def_id }
     }
 
     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
-        let Static { ty, kind, def_id: _ } = self;
-
-        ty.visit_with(visitor) || kind.visit_with(visitor)
-    }
-}
+        let Static { ty, def_id: _ } = self;
 
-impl<'tcx> TypeFoldable<'tcx> for StaticKind {
-    fn super_fold_with<F: TypeFolder<'tcx>>(&self, _folder: &mut F) -> Self {
-        match self {
-            StaticKind::Static => StaticKind::Static,
-        }
-    }
-
-    fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {
-        match self {
-            StaticKind::Static => false,
-        }
+        ty.visit_with(visitor)
     }
 }
 
index 9173c328006411cda989ebe0f3d2d0bd22da4b4a..3924a1aa47edab17a3df8ec5c6296c6ebaefcd49 100644 (file)
@@ -712,7 +712,7 @@ fn super_place_base(&mut self,
                     PlaceBase::Local(local) => {
                         self.visit_local(local, context, location);
                     }
-                    PlaceBase::Static(box Static { kind: _, ty, def_id: _ }) => {
+                    PlaceBase::Static(box Static { ty, def_id: _ }) => {
                         self.visit_ty(& $($mutability)? *ty, TyContext::Location(location));
                     }
                 }
index 639a98107cd56d15b603c5b6e1f028b9397fe3c0..49c3edbb2b3df1f699e91e7301fec7302f43c771 100644 (file)
@@ -438,12 +438,7 @@ pub fn codegen_place(
                 }
             }
             mir::PlaceRef {
-                base:
-                    mir::PlaceBase::Static(box mir::Static {
-                        ty,
-                        kind: mir::StaticKind::Static,
-                        def_id,
-                    }),
+                base: mir::PlaceBase::Static(box mir::Static { ty, def_id }),
                 projection: [],
             } => {
                 // NB: The layout of a static may be unsized as is the case when working
index d1c6ee8af58302e44fdc356d78a890c2b645fd8f..8ef4273a2f6a563a2b9c9ce4cb545a7ee342f3fd 100644 (file)
@@ -2,8 +2,8 @@
 
 use rustc::mir::{
     AggregateKind, Constant, Field, Local, LocalInfo, LocalKind, Location, Operand, Place,
-    PlaceBase, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Static, StaticKind,
-    Terminator, TerminatorKind,
+    PlaceBase, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Static, Terminator,
+    TerminatorKind,
 };
 use rustc::ty::layout::VariantIdx;
 use rustc::ty::print::Print;
@@ -172,10 +172,7 @@ fn append_place_to_string(
             PlaceRef { base: PlaceBase::Local(local), projection: [] } => {
                 self.append_local_to_string(*local, buf)?;
             }
-            PlaceRef {
-                base: PlaceBase::Static(box Static { kind: StaticKind::Static, def_id, .. }),
-                projection: [],
-            } => {
+            PlaceRef { base: PlaceBase::Static(box Static { def_id, .. }), projection: [] } => {
                 buf.push_str(&self.infcx.tcx.item_name(*def_id).to_string());
             }
             PlaceRef { base: &PlaceBase::Local(local), projection: [ProjectionElem::Deref] }
index 238a59490906c34b543f9ecdb3e7622203590ea4..6c9b811ebd0a85b3f49579bb786d76126be7cc7d 100644 (file)
@@ -5,7 +5,7 @@
 use rustc::lint::builtin::UNUSED_MUT;
 use rustc::mir::{
     read_only, Body, BodyAndCache, ClearCrossCrate, Local, Location, Mutability, Operand, Place,
-    PlaceBase, PlaceElem, PlaceRef, ReadOnlyBodyAndCache, Static, StaticKind,
+    PlaceBase, PlaceElem, PlaceRef, ReadOnlyBodyAndCache, Static,
 };
 use rustc::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind};
 use rustc::mir::{Field, ProjectionElem, Promoted, Rvalue, Statement, StatementKind};
@@ -2196,10 +2196,7 @@ fn is_mutable<'d>(
                     }),
                 }
             }
-            PlaceRef {
-                base: PlaceBase::Static(box Static { kind: StaticKind::Static, def_id, .. }),
-                projection: [],
-            } => {
+            PlaceRef { base: PlaceBase::Static(box Static { def_id, .. }), projection: [] } => {
                 if !self.infcx.tcx.is_mutable_static(*def_id) {
                     Err(place)
                 } else {
index 422bcd2b75c2581fc437c49e3d7da7611980dd10..815ace55a3721e1e6aa5d79ea12360cbd35088ef 100644 (file)
@@ -1,9 +1,7 @@
 use crate::borrow_check::ArtificialField;
 use crate::borrow_check::Overlap;
 use crate::borrow_check::{AccessDepth, Deep, Shallow};
-use rustc::mir::{
-    Body, BorrowKind, Place, PlaceBase, PlaceElem, PlaceRef, ProjectionElem, StaticKind,
-};
+use rustc::mir::{Body, BorrowKind, Place, PlaceBase, PlaceElem, PlaceRef, ProjectionElem};
 use rustc::ty::{self, TyCtxt};
 use rustc_hir as hir;
 use std::cmp::max;
@@ -327,20 +325,16 @@ fn place_base_conflict<'tcx>(
             }
         }
         (PlaceBase::Static(s1), PlaceBase::Static(s2)) => {
-            match (&s1.kind, &s2.kind) {
-                (StaticKind::Static, StaticKind::Static) => {
-                    if s1.def_id != s2.def_id {
-                        debug!("place_element_conflict: DISJOINT-STATIC");
-                        Overlap::Disjoint
-                    } else if tcx.is_mutable_static(s1.def_id) {
-                        // We ignore mutable statics - they can only be unsafe code.
-                        debug!("place_element_conflict: IGNORE-STATIC-MUT");
-                        Overlap::Disjoint
-                    } else {
-                        debug!("place_element_conflict: DISJOINT-OR-EQ-STATIC");
-                        Overlap::EqualOrDisjoint
-                    }
-                }
+            if s1.def_id != s2.def_id {
+                debug!("place_element_conflict: DISJOINT-STATIC");
+                Overlap::Disjoint
+            } else if tcx.is_mutable_static(s1.def_id) {
+                // We ignore mutable statics - they can only be unsafe code.
+                debug!("place_element_conflict: IGNORE-STATIC-MUT");
+                Overlap::Disjoint
+            } else {
+                debug!("place_element_conflict: DISJOINT-OR-EQ-STATIC");
+                Overlap::EqualOrDisjoint
             }
         }
         (PlaceBase::Local(_), PlaceBase::Static(_))
index f66af1f04a3606be124e2af3b09a8391134078e6..f771330e2d7111e5612244432ca1dd4e20d50602 100644 (file)
@@ -467,7 +467,7 @@ fn sanitize_place(
 
         let mut place_ty = match &place.base {
             PlaceBase::Local(index) => PlaceTy::from_ty(self.body.local_decls[*index].ty),
-            PlaceBase::Static(box Static { kind, ty, def_id }) => {
+            PlaceBase::Static(box Static { ty, def_id }) => {
                 let san_ty = self.sanitize_type(place, ty);
                 let check_err =
                     |verifier: &mut TypeVerifier<'a, 'b, 'tcx>, place: &Place<'tcx>, ty, san_ty| {
@@ -487,14 +487,10 @@ fn sanitize_place(
                             );
                         };
                     };
-                match kind {
-                    StaticKind::Static => {
-                        let ty = self.tcx().type_of(*def_id);
-                        let ty = self.cx.normalize(ty, location);
+                let ty = self.tcx().type_of(*def_id);
+                let ty = self.cx.normalize(ty, location);
 
-                        check_err(self, place, ty, san_ty);
-                    }
-                }
+                check_err(self, place, ty, san_ty);
                 PlaceTy::from_ty(san_ty)
             }
         };
index 6d15827536c556cb2911977a30dbcd075ba817b1..3309e9b9b622ae8d33360cd831dcfeef82191dbe 100644 (file)
@@ -212,7 +212,7 @@ fn access_local(
         frame.locals[local].access()
     }
 
-    /// Called before a `StaticKind::Static` value is accessed.
+    /// Called before a `Static` value is accessed.
     fn before_access_static(
         _memory_extra: &Self::MemoryExtra,
         _allocation: &Allocation,
index 79411d872a959ab4bd73da7dbca37a9b631d9067..aa15f3d1f173eb7fbae274dfc8dd0f54f6503bb2 100644 (file)
@@ -625,33 +625,27 @@ pub(super) fn eval_static_to_mplace(
         &self,
         place_static: &mir::Static<'tcx>,
     ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
-        use rustc::mir::StaticKind;
-
-        Ok(match place_static.kind {
-            StaticKind::Static => {
-                let ty = place_static.ty;
-                assert!(!ty.needs_subst());
-                let layout = self.layout_of(ty)?;
-                // Just create a lazy reference, so we can support recursive statics.
-                // tcx takes care of assigning every static one and only one unique AllocId.
-                // When the data here is ever actually used, memory will notice,
-                // and it knows how to deal with alloc_id that are present in the
-                // global table but not in its local memory: It calls back into tcx through
-                // a query, triggering the CTFE machinery to actually turn this lazy reference
-                // into a bunch of bytes.  IOW, statics are evaluated with CTFE even when
-                // this InterpCx uses another Machine (e.g., in miri).  This is what we
-                // want!  This way, computing statics works consistently between codegen
-                // and miri: They use the same query to eventually obtain a `ty::Const`
-                // and use that for further computation.
-                //
-                // Notice that statics have *two* AllocIds: the lazy one, and the resolved
-                // one.  Here we make sure that the interpreted program never sees the
-                // resolved ID.  Also see the doc comment of `Memory::get_static_alloc`.
-                let alloc_id = self.tcx.alloc_map.lock().create_static_alloc(place_static.def_id);
-                let ptr = self.tag_static_base_pointer(Pointer::from(alloc_id));
-                MPlaceTy::from_aligned_ptr(ptr, layout)
-            }
-        })
+        let ty = place_static.ty;
+        assert!(!ty.needs_subst());
+        let layout = self.layout_of(ty)?;
+        // Just create a lazy reference, so we can support recursive statics.
+        // tcx takes care of assigning every static one and only one unique AllocId.
+        // When the data here is ever actually used, memory will notice,
+        // and it knows how to deal with alloc_id that are present in the
+        // global table but not in its local memory: It calls back into tcx through
+        // a query, triggering the CTFE machinery to actually turn this lazy reference
+        // into a bunch of bytes.  IOW, statics are evaluated with CTFE even when
+        // this InterpCx uses another Machine (e.g., in miri).  This is what we
+        // want!  This way, computing statics works consistently between codegen
+        // and miri: They use the same query to eventually obtain a `ty::Const`
+        // and use that for further computation.
+        //
+        // Notice that statics have *two* AllocIds: the lazy one, and the resolved
+        // one.  Here we make sure that the interpreted program never sees the
+        // resolved ID.  Also see the doc comment of `Memory::get_static_alloc`.
+        let alloc_id = self.tcx.alloc_map.lock().create_static_alloc(place_static.def_id);
+        let ptr = self.tag_static_base_pointer(Pointer::from(alloc_id));
+        Ok(MPlaceTy::from_aligned_ptr(ptr, layout))
     }
 
     /// Computes a place. You should only use this if you intend to write into this
index 84b641a763a024cd91661f47051253091a93f053..2ecae7c6b0cd82473f3f8e3d5dd1ba3689cf2e1e 100644 (file)
 use rustc::mir::interpret::{ErrorHandled, GlobalAlloc, Scalar};
 use rustc::mir::mono::{InstantiationMode, MonoItem};
 use rustc::mir::visit::Visitor as MirVisitor;
-use rustc::mir::{self, Location, PlaceBase, Static, StaticKind};
+use rustc::mir::{self, Location, PlaceBase, Static};
 use rustc::session::config::EntryFnType;
 use rustc::ty::adjustment::{CustomCoerceUnsized, PointerCast};
 use rustc::ty::print::obsolete::DefPathBasedNames;
@@ -647,7 +647,7 @@ fn visit_place_base(
         location: Location,
     ) {
         match place_base {
-            PlaceBase::Static(box Static { kind: StaticKind::Static, def_id, .. }) => {
+            PlaceBase::Static(box Static { def_id, .. }) => {
                 debug!("visiting static {:?} @ {:?}", def_id, location);
 
                 let tcx = self.tcx;
index 88fce075d7c02f76a22cb654945031c809b5d8e4..be9c2b741a2692eb56dd9f0ef765d5d8b7029817 100644 (file)
@@ -194,8 +194,8 @@ fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location:
             PlaceBase::Local(..) => {
                 // Locals are safe.
             }
-            PlaceBase::Static(box Static { kind: StaticKind::Static, .. }) => {
-                bug!("StaticKind::Static should not exist");
+            PlaceBase::Static(box Static { .. }) => {
+                bug!("Static should not exist");
             }
         }
 
index 1052d037326b4e7a67aebf2e9ef3ca3939ff5c4e..76f1e2d186e619442f8a7ddf9f8e9d1396a43aa1 100644 (file)
@@ -39,7 +39,7 @@
 /// errors when promotion of `#[rustc_args_required_const]` arguments fails.
 ///
 /// After this pass is run, `promoted_fragments` will hold the MIR body corresponding to each
-/// newly created `StaticKind::Promoted`.
+/// newly created `Constant`.
 #[derive(Default)]
 pub struct PromoteTemps<'tcx> {
     pub promoted_fragments: Cell<IndexVec<Promoted, BodyAndCache<'tcx>>>,