)]
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
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> {
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)
}
}
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)
}
}
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));
}
}
}
}
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
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;
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] }
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};
}),
}
}
- 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 {
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;
}
}
(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(_))
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| {
);
};
};
- 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)
}
};
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,
&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
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;
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;
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");
}
}
/// 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>>>,