})
}
- /// Returns `true` if the node pointed to by `def_id` is a static item, and its mutability.
- pub fn is_static(&self, def_id: DefId) -> Option<hir::Mutability> {
- self.static_mutability(def_id)
+ /// Returns `true` if the node pointed to by `def_id` is a `static` item.
+ pub fn is_static(&self, def_id: DefId) -> bool {
+ self.static_mutability(def_id).is_some()
+ }
+
+ /// Returns `true` if the node pointed to by `def_id` is a mutable `static` item.
+ pub fn is_mutable_static(&self, def_id: DefId) -> bool {
+ self.static_mutability(def_id) == Some(hir::MutMutable)
}
/// Expands the given impl trait type, stopping if the type is recursive.
self.get_fn(fn_instance)
}
Some(AllocKind::Static(def_id)) => {
- assert!(self.tcx.is_static(def_id).is_some());
+ assert!(self.tcx.is_static(def_id));
self.get_static(def_id)
}
None => bug!("missing allocation {:?}", ptr.alloc_id),
fn check_const(cx: &LateContext<'_, '_>, body_id: hir::BodyId) {
let def_id = cx.tcx.hir().body_owner_def_id(body_id);
- let is_static = cx.tcx.is_static(def_id).is_some();
- let param_env = if is_static {
+ let param_env = if cx.tcx.is_static(def_id) {
// Use the same param_env as `codegen_static_initializer`, to reuse the cache.
ty::ParamEnv::reveal_all()
} else {
is_local_mutation_allowed,
}),
Place::Base(PlaceBase::Static(box Static{ kind: StaticKind::Static(def_id), .. })) => {
- if self.infcx.tcx.is_static(def_id) != Some(hir::Mutability::MutMutable) {
+ if !self.infcx.tcx.is_mutable_static(def_id) {
Err(place)
} else {
Ok(RootPlace {
..
}) = self.borrowck_context
{
- if tcx.is_static(*def_id).is_some() {
+ if tcx.is_static(*def_id) {
ConstraintCategory::UseAsStatic
} else {
ConstraintCategory::UseAsConst
..
}) = self.borrowck_context
{
- if tcx.is_static(*def_id).is_some() {
+ if tcx.is_static(*def_id) {
ConstraintCategory::UseAsStatic
} else {
ConstraintCategory::UseAsConst
Place::Base(PlaceBase::Static(box Static{ kind: StaticKind::Promoted(_), .. })) =>
false,
Place::Base(PlaceBase::Static(box Static{ kind: StaticKind::Static(def_id), .. })) => {
- tcx.is_static(*def_id) == Some(hir::Mutability::MutMutable)
+ tcx.is_mutable_static(*def_id)
}
Place::Projection(proj) => match proj.elem {
ProjectionElem::Field(..)
if def_id_1 != def_id_2 {
debug!("place_element_conflict: DISJOINT-STATIC");
Overlap::Disjoint
- } else if tcx.is_static(*def_id_1) == Some(hir::Mutability::MutMutable) {
+ } else if tcx.is_mutable_static(*def_id_1) {
// We ignore mutable statics - they can only be unsafe code.
debug!("place_element_conflict: IGNORE-STATIC-MUT");
Overlap::Disjoint
use std::hash::Hash;
use std::collections::hash_map::Entry;
-use rustc::hir::{self, def_id::DefId};
use rustc::hir::def::Def;
+use rustc::hir::def_id::DefId;
use rustc::mir::interpret::{ConstEvalErr, ErrorHandled};
use rustc::mir;
use rustc::ty::{self, TyCtxt, query::TyCtxtAt};
ecx.run()?;
// Intern the result
- let internally_mutable = !layout.ty.is_freeze(tcx, param_env, mir.span);
- let is_static = tcx.is_static(cid.instance.def_id());
- let mutability = if is_static == Some(hir::Mutability::MutMutable) || internally_mutable {
+ let mutability = if tcx.is_mutable_static(cid.instance.def_id()) ||
+ !layout.ty.is_freeze(tcx, param_env, mir.span) {
Mutability::Mutable
} else {
Mutability::Immutable
}
// Now that we validated, turn this into a proper constant.
let def_id = cid.instance.def.def_id();
- if tcx.is_static(def_id).is_some() || cid.promoted.is_some() {
+ if tcx.is_static(def_id) || cid.promoted.is_some() {
Ok(mplace_to_const(&ecx, mplace))
} else {
Ok(op_to_const(&ecx, mplace.into()))
}).map_err(|error| {
let err = error_to_const_error(&ecx, error);
// errors in statics are always emitted as fatal errors
- if tcx.is_static(def_id).is_some() {
+ if tcx.is_static(def_id) {
// Ensure that if the above error was either `TooGeneric` or `Reported`
// an error must be reported.
let reported_err = tcx.sess.track_errors(|| {
&self,
gid: GlobalId<'tcx>,
) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
- let param_env = if self.tcx.is_static(gid.instance.def_id()).is_some() {
+ let param_env = if self.tcx.is_static(gid.instance.def_id()) {
ty::ParamEnv::reveal_all()
} else {
self.param_env
// full query anyway
tcx.const_eval_raw(ty::ParamEnv::reveal_all().and(gid)).map_err(|err| {
// no need to report anything, the const_eval call takes care of that for statics
- assert!(tcx.is_static(def_id).is_some());
+ assert!(tcx.is_static(def_id));
match err {
ErrorHandled::Reported => InterpError::ReferencedConstant.into(),
ErrorHandled::TooGeneric => InterpError::TooGeneric.into(),
&Place::Base(
PlaceBase::Static(box Static { kind: StaticKind::Static(def_id), .. })
) => {
- if self.tcx.is_static(def_id) == Some(hir::Mutability::MutMutable) {
+ if self.tcx.is_mutable_static(def_id) {
self.require_unsafe("use of mutable static",
"mutable statics can be mutated by multiple threads: aliasing violations \
or data races will cause undefined behavior",