]> git.lizzy.rs Git - rust.git/commitdiff
Change return type of `TyCtxt::is_static` to bool
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sun, 21 Apr 2019 11:41:51 +0000 (14:41 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sun, 21 Apr 2019 11:41:51 +0000 (14:41 +0300)
Add `TyCtxt::is_mutable_static`

src/librustc/ty/util.rs
src/librustc_codegen_llvm/common.rs
src/librustc_lint/builtin.rs
src/librustc_mir/borrow_check/mod.rs
src/librustc_mir/borrow_check/nll/type_check/mod.rs
src/librustc_mir/borrow_check/place_ext.rs
src/librustc_mir/borrow_check/places_conflict.rs
src/librustc_mir/const_eval.rs
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/memory.rs
src/librustc_mir/transform/check_unsafety.rs

index d808387e269fd594fbe7e21da16bb245de22a787..67507f7b5d11647b4b6614f79605c3cabf7d8193 100644 (file)
@@ -612,9 +612,14 @@ pub fn empty_substs_for_def_id(self, item_def_id: DefId) -> SubstsRef<'tcx> {
         })
     }
 
-    /// 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.
index 9554e54e4142ae207105b317ba324574e97819b6..b9fd9629e6ff193ba17f007c7a12c290b92ce17e 100644 (file)
@@ -322,7 +322,7 @@ fn scalar_to_backend(
                         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),
index f289b0b48fbdf3f926721532cefc266b64e3b395..5fde4331d4702778a8754be0c437f8698c0fb5f2 100644 (file)
@@ -1171,8 +1171,7 @@ fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item) {
 
 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 {
index 0b2c90b9160453993facdef22bd0a23c67daa097..43ed85d4ac5412de47fd0bea0481b0a616057364 100644 (file)
@@ -2117,7 +2117,7 @@ fn is_mutable<'d>(
                     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 {
index d123f3e405936542aac55a38364c6e7b84f81301..ce8f1852551f2c875523ef4e5dffa0163f19d480 100644 (file)
@@ -1321,7 +1321,7 @@ fn check_stmt(&mut self, mir: &Mir<'tcx>, stmt: &Statement<'tcx>, location: Loca
                         ..
                     }) = self.borrowck_context
                     {
-                        if tcx.is_static(*def_id).is_some() {
+                        if tcx.is_static(*def_id) {
                             ConstraintCategory::UseAsStatic
                         } else {
                             ConstraintCategory::UseAsConst
@@ -1626,7 +1626,7 @@ fn check_call_dest(
                             ..
                         }) = self.borrowck_context
                         {
-                            if tcx.is_static(*def_id).is_some() {
+                            if tcx.is_static(*def_id) {
                                 ConstraintCategory::UseAsStatic
                             } else {
                                 ConstraintCategory::UseAsConst
index 8269b7b95f490ea4ac88e6e5118d3b74afe9d77c..913884a8218372567251a9cbd759cbcda881c931 100644 (file)
@@ -52,7 +52,7 @@ fn ignore_borrow(
             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(..)
index cebf05ad9b99df2047b590f9e46e2dc7687247c5..1bf606109dc76b295b1d141aa18691f7961e5816 100644 (file)
@@ -321,7 +321,7 @@ fn place_base_conflict<'a, 'gcx: 'tcx, 'tcx>(
                     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
index 09c50d4f81f494e17c01636371fffbc21027ae39..b65f2ba2601e44927c2a4cfc17dd006eacaf3da3 100644 (file)
@@ -6,8 +6,8 @@
 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};
@@ -158,9 +158,8 @@ fn eval_body_using_ecx<'mir, 'tcx>(
     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
@@ -533,7 +532,7 @@ fn validate_and_turn_into_const<'a, 'tcx>(
         }
         // 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()))
@@ -628,7 +627,7 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
     }).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(|| {
index 32f7ecd97b2ef13caa44d56d680c400233d4f2ce..4ae8bfe854d786d5c65d69eede3bb375b81acba9 100644 (file)
@@ -634,7 +634,7 @@ pub fn const_eval_raw(
         &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
index 117bd15399cde336807be187951da319842a3d9d..9674822b47a3ddb7302997e509b7ac9a9d798d05 100644 (file)
@@ -342,7 +342,7 @@ fn get_static_alloc(
         // 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(),
index c9cccb2b03ac4ec9dad19cdd7e8c3d5af9a60cd1..87c02b7f01da32ba322250aac8d71eb0e34897e8 100644 (file)
@@ -306,7 +306,7 @@ fn visit_place(&mut self,
             &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",