-use rustc::hir::intravisit;
+use rustc::hir::map::Map;
use rustc::lint::builtin::{SAFE_PACKED_BORROWS, UNUSED_UNSAFE};
use rustc::mir::visit::{MutatingUseContext, PlaceContext, Visitor};
use rustc::mir::*;
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
+use rustc_hir::intravisit;
use rustc_hir::Node;
use rustc_span::symbol::{sym, Symbol};
use std::ops::Bound;
+use crate::const_eval::{is_const_fn, is_min_const_fn};
use crate::util;
use rustc_error_codes::*;
}
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: Location) {
- match place.base {
- PlaceBase::Local(..) => {
- // Locals are safe.
- }
- PlaceBase::Static(box Static { kind: StaticKind::Promoted(_, _), .. }) => {
- bug!("unsafety checking should happen before promotion");
- }
- PlaceBase::Static(box Static { kind: StaticKind::Static, .. }) => {
- bug!("StaticKind::Static should not exist");
- }
- }
-
for (i, elem) in place.projection.iter().enumerate() {
let proj_base = &place.projection[..i];
}
}
let is_borrow_of_interior_mut = context.is_borrow()
- && !Place::ty_from(&place.base, proj_base, self.body, self.tcx).ty.is_freeze(
+ && !Place::ty_from(&place.local, proj_base, self.body, self.tcx).ty.is_freeze(
self.tcx,
self.param_env,
self.source_info.span,
self.check_mut_borrowing_layout_constrained_field(place, context.is_mutating_use());
}
let old_source_info = self.source_info;
- if let (PlaceBase::Local(local), []) = (&place.base, proj_base) {
+ if let (local, []) = (&place.local, proj_base) {
let decl = &self.body.local_decls[*local];
if decl.internal {
// Internal locals are used in the `move_val_init` desugaring.
}
}
}
- let base_ty = Place::ty_from(&place.base, proj_base, self.body, self.tcx).ty;
+ let base_ty = Place::ty_from(&place.local, proj_base, self.body, self.tcx).ty;
match base_ty.kind {
ty::RawPtr(..) => self.require_unsafe(
"dereference of raw pointer",
match elem {
ProjectionElem::Field(..) => {
let ty =
- Place::ty_from(&place.base, proj_base, &self.body.local_decls, self.tcx).ty;
+ Place::ty_from(&place.local, proj_base, &self.body.local_decls, self.tcx)
+ .ty;
match ty.kind {
ty::Adt(def, _) => match self.tcx.layout_scalar_valid_range(def.did) {
(Bound::Unbounded, Bound::Unbounded) => {}
}
impl<'a, 'tcx> intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'a> {
- fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> {
+ type Map = Map<'tcx>;
+
+ fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, Self::Map> {
intravisit::NestedVisitorMap::None
}
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
let (const_context, min_const_fn) = match tcx.hir().body_owner_kind(id) {
hir::BodyOwnerKind::Closure => (false, false),
- hir::BodyOwnerKind::Fn => (tcx.is_const_fn(def_id), tcx.is_min_const_fn(def_id)),
+ hir::BodyOwnerKind::Fn => (is_const_fn(tcx, def_id), is_min_const_fn(tcx, def_id)),
hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => (true, false),
};
let mut checker = UnsafetyChecker::new(const_context, min_const_fn, body, tcx, param_env);