about summary refs log tree commit diff
diff options
context:
space:
mode:
authormarmeladema <xademax@gmail.com>2020-04-17 15:25:44 +0100
committermarmeladema <xademax@gmail.com>2020-04-27 21:50:17 +0100
commitabd31ad6e8d709fa09b02eea77310c8cc19aa1ed (patch)
treed056730c5057029b072a8c56c0ef51e6f3b33fb0
parentde7c9e753d449a02a39610cf657c11dc6af86774 (diff)
downloadrust-abd31ad6e8d709fa09b02eea77310c8cc19aa1ed.tar.gz
rust-abd31ad6e8d709fa09b02eea77310c8cc19aa1ed.zip
Use `LocalDefId` in `unsafety_check_result` query
-rw-r--r--src/librustc_middle/query/mod.rs6
-rw-r--r--src/librustc_mir/transform/check_unsafety.rs20
-rw-r--r--src/librustc_mir/transform/mod.rs2
3 files changed, 13 insertions, 15 deletions
diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs
index be9811a9c12..fdefb8eee2e 100644
--- a/src/librustc_middle/query/mod.rs
+++ b/src/librustc_middle/query/mod.rs
@@ -389,9 +389,9 @@ rustc_queries! {
 
     TypeChecking {
         /// The result of unsafety-checking this `DefId`.
-        query unsafety_check_result(key: DefId) -> mir::UnsafetyCheckResult {
-            desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key) }
-            cache_on_disk_if { key.is_local() }
+        query unsafety_check_result(key: LocalDefId) -> mir::UnsafetyCheckResult {
+            desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
+            cache_on_disk_if { true }
         }
 
         /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error
diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs
index 567fb61e0e8..1c1560cbf9d 100644
--- a/src/librustc_mir/transform/check_unsafety.rs
+++ b/src/librustc_mir/transform/check_unsafety.rs
@@ -132,7 +132,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
                 }
                 &AggregateKind::Closure(def_id, _) | &AggregateKind::Generator(def_id, _, _) => {
                     let UnsafetyCheckResult { violations, unsafe_blocks } =
-                        self.tcx.unsafety_check_result(def_id);
+                        self.tcx.unsafety_check_result(def_id.expect_local());
                     self.register_violations(&violations, &unsafe_blocks);
                 }
             },
@@ -485,7 +485,7 @@ fn check_unused_unsafe(
     intravisit::Visitor::visit_body(&mut visitor, body);
 }
 
-fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult {
+fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: LocalDefId) -> UnsafetyCheckResult {
     debug!("unsafety_violations({:?})", def_id);
 
     // N.B., this borrow is valid because all the consumers of
@@ -494,21 +494,18 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult
 
     let param_env = tcx.param_env(def_id);
 
-    let id = tcx.hir().as_local_hir_id(def_id.expect_local());
+    let id = tcx.hir().as_local_hir_id(def_id);
     let (const_context, min_const_fn) = match tcx.hir().body_owner_kind(id) {
         hir::BodyOwnerKind::Closure => (false, false),
-        hir::BodyOwnerKind::Fn => (is_const_fn(tcx, def_id), is_min_const_fn(tcx, def_id)),
+        hir::BodyOwnerKind::Fn => {
+            (is_const_fn(tcx, def_id.to_def_id()), is_min_const_fn(tcx, def_id.to_def_id()))
+        }
         hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => (true, false),
     };
     let mut checker = UnsafetyChecker::new(const_context, min_const_fn, body, tcx, param_env);
     checker.visit_body(&body);
 
-    check_unused_unsafe(
-        tcx,
-        def_id.expect_local(),
-        &checker.used_unsafe,
-        &mut checker.inherited_blocks,
-    );
+    check_unused_unsafe(tcx, def_id, &checker.used_unsafe, &mut checker.inherited_blocks);
     UnsafetyCheckResult {
         violations: checker.violations.into(),
         unsafe_blocks: checker.inherited_blocks.into(),
@@ -600,7 +597,8 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
         return;
     }
 
-    let UnsafetyCheckResult { violations, unsafe_blocks } = tcx.unsafety_check_result(def_id);
+    let UnsafetyCheckResult { violations, unsafe_blocks } =
+        tcx.unsafety_check_result(def_id.expect_local());
 
     for &UnsafetyViolation { source_info, description, details, kind } in violations.iter() {
         // Report an error.
diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs
index b9701aed753..a13ecdccc43 100644
--- a/src/librustc_mir/transform/mod.rs
+++ b/src/librustc_mir/transform/mod.rs
@@ -212,7 +212,7 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs {
 
 fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> &Steal<Body<'_>> {
     // Unsafety check uses the raw mir, so make sure it is run
-    let _ = tcx.unsafety_check_result(def_id);
+    let _ = tcx.unsafety_check_result(def_id.expect_local());
 
     let mut body = tcx.mir_built(def_id).steal();