mir-borrowck: Move is_static_mut()
to ty/utils.rs
This commit is contained in:
parent
8efbf7a4f0
commit
0bb77bdb54
@ -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 @@ pub fn const_usize(&self, val: u16) -> ConstInt {
|
||||
_ => 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> {
|
||||
|
@ -14,9 +14,8 @@
|
||||
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 @@ fn visit_lvalue(&mut self,
|
||||
// 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 @@ fn visit_lvalue(&mut self,
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user