diff options
| author | Basile Desloges <basile.desloges@gmail.com> | 2017-11-12 12:40:56 +0100 |
|---|---|---|
| committer | Basile Desloges <basile.desloges@gmail.com> | 2017-11-13 21:53:09 +0100 |
| commit | 0bb77bdb5423402b583372abf2f097be6b4e46bc (patch) | |
| tree | b89e6c807b52f9ff480fc4fa74c6a76b4808f8ab /src | |
| parent | 8efbf7a4f0e44a490d3379b102b7b13ee0152ab9 (diff) | |
| download | rust-0bb77bdb5423402b583372abf2f097be6b4e46bc.tar.gz rust-0bb77bdb5423402b583372abf2f097be6b4e46bc.zip | |
mir-borrowck: Move `is_static_mut()` to `ty/utils.rs`
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/ty/util.rs | 23 | ||||
| -rw-r--r-- | src/librustc_mir/transform/check_unsafety.rs | 23 |
2 files changed, 24 insertions, 22 deletions
diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index d12a973017d..aa07a6b070e 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -10,8 +10,9 @@ //! misc. type-system utilities too small to deserve their own file +use hir::def::Def; use hir::def_id::{DefId, LOCAL_CRATE}; -use hir::map::DefPathData; +use hir::map::{DefPathData, Node}; use hir; use ich::NodeIdHashingMode; use middle::const_val::ConstVal; @@ -648,6 +649,26 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { _ => bug!(), } } + + /// Check if the node pointed to by def_id is a mutable static item + pub fn is_static_mut(&self, def_id: DefId) -> bool { + if let Some(node) = self.hir.get_if_local(def_id) { + match node { + Node::NodeItem(&hir::Item { + node: hir::ItemStatic(_, hir::MutMutable, _), .. + }) => true, + Node::NodeForeignItem(&hir::ForeignItem { + node: hir::ForeignItemStatic(_, mutbl), .. + }) => mutbl, + _ => false + } + } else { + match self.describe_def(def_id) { + Some(Def::Static(_, mutbl)) => mutbl, + _ => false + } + } + } } pub struct TypeIdHasher<'a, 'gcx: 'a+'tcx, 'tcx: 'a, W> { diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 53a4b2551fd..cbf1b0b0899 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -14,9 +14,8 @@ use rustc_data_structures::indexed_vec::IndexVec; use rustc::ty::maps::Providers; use rustc::ty::{self, TyCtxt}; use rustc::hir; -use rustc::hir::def::Def; use rustc::hir::def_id::DefId; -use rustc::hir::map::{DefPathData, Node}; +use rustc::hir::map::DefPathData; use rustc::lint::builtin::{SAFE_EXTERN_STATICS, UNUSED_UNSAFE}; use rustc::mir::*; use rustc::mir::visit::{LvalueContext, Visitor}; @@ -189,7 +188,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> { // locals are safe } &Lvalue::Static(box Static { def_id, ty: _ }) => { - if self.is_static_mut(def_id) { + if self.tcx.is_static_mut(def_id) { self.require_unsafe("use of mutable static"); } else if self.tcx.is_foreign_item(def_id) { let source_info = self.source_info; @@ -208,24 +207,6 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> { } impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { - fn is_static_mut(&self, def_id: DefId) -> bool { - if let Some(node) = self.tcx.hir.get_if_local(def_id) { - match node { - Node::NodeItem(&hir::Item { - node: hir::ItemStatic(_, hir::MutMutable, _), .. - }) => true, - Node::NodeForeignItem(&hir::ForeignItem { - node: hir::ForeignItemStatic(_, mutbl), .. - }) => mutbl, - _ => false - } - } else { - match self.tcx.describe_def(def_id) { - Some(Def::Static(_, mutbl)) => mutbl, - _ => false - } - } - } fn require_unsafe(&mut self, description: &'static str) { |
