about summary refs log tree commit diff
path: root/src/librustc_mir/transform/check_unsafety.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustc_mir/transform/check_unsafety.rs')
-rw-r--r--src/librustc_mir/transform/check_unsafety.rs59
1 files changed, 29 insertions, 30 deletions
diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs
index 66529e57983..3ed63d749cd 100644
--- a/src/librustc_mir/transform/check_unsafety.rs
+++ b/src/librustc_mir/transform/check_unsafety.rs
@@ -12,7 +12,6 @@ use rustc::lint::builtin::{SAFE_EXTERN_STATICS, SAFE_PACKED_BORROWS, UNUSED_UNSA
 use rustc::mir::*;
 use rustc::mir::visit::{PlaceContext, Visitor, MutatingUseContext};
 
-use syntax::ast;
 use syntax::symbol::Symbol;
 
 use std::ops::Bound;
@@ -29,8 +28,8 @@ pub struct UnsafetyChecker<'a, 'tcx: 'a> {
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
     param_env: ty::ParamEnv<'tcx>,
     /// Mark an `unsafe` block as used, so we don't lint it.
-    used_unsafe: FxHashSet<ast::NodeId>,
-    inherited_blocks: Vec<(ast::NodeId, bool)>,
+    used_unsafe: FxHashSet<hir::HirId>,
+    inherited_blocks: Vec<(hir::HirId, bool)>,
 }
 
 impl<'a, 'gcx, 'tcx> UnsafetyChecker<'a, 'tcx> {
@@ -349,7 +348,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
 
     fn register_violations(&mut self,
                            violations: &[UnsafetyViolation],
-                           unsafe_blocks: &[(ast::NodeId, bool)]) {
+                           unsafe_blocks: &[(hir::HirId, bool)]) {
         let safety = self.source_scope_local_data[self.source_info.scope].safety;
         let within_unsafe = match safety {
             // `unsafe` blocks are required in safe code
@@ -375,10 +374,10 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
             }
             // `unsafe` function bodies allow unsafe without additional unsafe blocks
             Safety::BuiltinUnsafe | Safety::FnUnsafe => true,
-            Safety::ExplicitUnsafe(node_id) => {
+            Safety::ExplicitUnsafe(hir_id) => {
                 // mark unsafe block as used if there are any unsafe operations inside
                 if !violations.is_empty() {
-                    self.used_unsafe.insert(node_id);
+                    self.used_unsafe.insert(hir_id);
                 }
                 // only some unsafety is allowed in const fn
                 if self.min_const_fn {
@@ -405,8 +404,8 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
                 true
             }
         };
-        self.inherited_blocks.extend(unsafe_blocks.iter().map(|&(node_id, is_used)| {
-            (node_id, is_used && !within_unsafe)
+        self.inherited_blocks.extend(unsafe_blocks.iter().map(|&(hir_id, is_used)| {
+            (hir_id, is_used && !within_unsafe)
         }));
     }
     fn check_mut_borrowing_layout_constrained_field(
@@ -467,8 +466,8 @@ pub(crate) fn provide(providers: &mut Providers<'_>) {
 }
 
 struct UnusedUnsafeVisitor<'a> {
-    used_unsafe: &'a FxHashSet<ast::NodeId>,
-    unsafe_blocks: &'a mut Vec<(ast::NodeId, bool)>,
+    used_unsafe: &'a FxHashSet<hir::HirId>,
+    unsafe_blocks: &'a mut Vec<(hir::HirId, bool)>,
 }
 
 impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'a> {
@@ -482,19 +481,19 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'a> {
         hir::intravisit::walk_block(self, block);
 
         if let hir::UnsafeBlock(hir::UserProvided) = block.rules {
-            self.unsafe_blocks.push((block.id, self.used_unsafe.contains(&block.id)));
+            self.unsafe_blocks.push((block.hir_id, self.used_unsafe.contains(&block.hir_id)));
         }
     }
 }
 
 fn check_unused_unsafe<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                                  def_id: DefId,
-                                 used_unsafe: &FxHashSet<ast::NodeId>,
-                                 unsafe_blocks: &'a mut Vec<(ast::NodeId, bool)>)
+                                 used_unsafe: &FxHashSet<hir::HirId>,
+                                 unsafe_blocks: &'a mut Vec<(hir::HirId, bool)>)
 {
     let body_id =
-        tcx.hir().as_local_node_id(def_id).and_then(|node_id| {
-            tcx.hir().maybe_body_owned_by(node_id)
+        tcx.hir().as_local_hir_id(def_id).and_then(|hir_id| {
+            tcx.hir().maybe_body_owned_by_by_hir_id(hir_id)
         });
 
     let body_id = match body_id {
@@ -574,18 +573,18 @@ fn unsafe_derive_on_repr_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: D
                   &message);
 }
 
-/// Returns the `NodeId` for an enclosing scope that is also `unsafe`.
+/// Returns the `HirId` for an enclosing scope that is also `unsafe`.
 fn is_enclosed(tcx: TyCtxt<'_, '_, '_>,
-               used_unsafe: &FxHashSet<ast::NodeId>,
-               id: ast::NodeId) -> Option<(String, ast::NodeId)> {
-    let parent_id = tcx.hir().get_parent_node(id);
+               used_unsafe: &FxHashSet<hir::HirId>,
+               id: hir::HirId) -> Option<(String, hir::HirId)> {
+    let parent_id = tcx.hir().get_parent_node_by_hir_id(id);
     if parent_id != id {
         if used_unsafe.contains(&parent_id) {
             Some(("block".to_string(), parent_id))
         } else if let Some(Node::Item(&hir::Item {
             node: hir::ItemKind::Fn(_, header, _, _),
             ..
-        })) = tcx.hir().find(parent_id) {
+        })) = tcx.hir().find_by_hir_id(parent_id) {
             match header.unsafety {
                 hir::Unsafety::Unsafe => Some(("fn".to_string(), parent_id)),
                 hir::Unsafety::Normal => None,
@@ -599,14 +598,14 @@ fn is_enclosed(tcx: TyCtxt<'_, '_, '_>,
 }
 
 fn report_unused_unsafe(tcx: TyCtxt<'_, '_, '_>,
-                        used_unsafe: &FxHashSet<ast::NodeId>,
-                        id: ast::NodeId) {
-    let span = tcx.sess.source_map().def_span(tcx.hir().span(id));
+                        used_unsafe: &FxHashSet<hir::HirId>,
+                        id: hir::HirId) {
+    let span = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(id));
     let msg = "unnecessary `unsafe` block";
-    let mut db = tcx.struct_span_lint_node(UNUSED_UNSAFE, id, span, msg);
+    let mut db = tcx.struct_span_lint_hir(UNUSED_UNSAFE, id, span, msg);
     db.span_label(span, msg);
     if let Some((kind, id)) = is_enclosed(tcx, used_unsafe, id) {
-        db.span_label(tcx.sess.source_map().def_span(tcx.hir().span(id)),
+        db.span_label(tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(id)),
                       format!("because it's nested under this `unsafe` {}", kind));
     }
     db.emit();
@@ -655,20 +654,20 @@ pub fn check_unsafety<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
                     .note(&details.as_str()[..])
                     .emit();
             }
-            UnsafetyViolationKind::ExternStatic(lint_node_id) => {
+            UnsafetyViolationKind::ExternStatic(lint_hir_id) => {
                 tcx.lint_node_note(SAFE_EXTERN_STATICS,
-                              lint_node_id,
+                              lint_hir_id,
                               source_info.span,
                               &format!("{} is unsafe and requires unsafe function or block \
                                         (error E0133)", &description.as_str()[..]),
                               &details.as_str()[..]);
             }
-            UnsafetyViolationKind::BorrowPacked(lint_node_id) => {
+            UnsafetyViolationKind::BorrowPacked(lint_hir_id) => {
                 if let Some(impl_def_id) = builtin_derive_def_id(tcx, def_id) {
                     tcx.unsafe_derive_on_repr_packed(impl_def_id);
                 } else {
                     tcx.lint_node_note(SAFE_PACKED_BORROWS,
-                                  lint_node_id,
+                                  lint_hir_id,
                                   source_info.span,
                                   &format!("{} is unsafe and requires unsafe function or block \
                                             (error E0133)", &description.as_str()[..]),
@@ -679,7 +678,7 @@ pub fn check_unsafety<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
     }
 
     let mut unsafe_blocks: Vec<_> = unsafe_blocks.into_iter().collect();
-    unsafe_blocks.sort();
+    unsafe_blocks.sort_by_cached_key(|(hir_id, _)| tcx.hir().hir_to_node_id(*hir_id));
     let used_unsafe: FxHashSet<_> = unsafe_blocks.iter()
         .flat_map(|&&(id, used)| if used { Some(id) } else { None })
         .collect();