Skip to content

Commit afe4b1b

Browse files
committed
Use LocalDefId in unsafety_check_result query
1 parent 169c399 commit afe4b1b

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

src/librustc_middle/query/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,9 @@ rustc_queries! {
389389

390390
TypeChecking {
391391
/// The result of unsafety-checking this `DefId`.
392-
query unsafety_check_result(key: DefId) -> mir::UnsafetyCheckResult {
393-
desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key) }
394-
cache_on_disk_if { key.is_local() }
392+
query unsafety_check_result(key: LocalDefId) -> mir::UnsafetyCheckResult {
393+
desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
394+
cache_on_disk_if { true }
395395
}
396396

397397
/// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error

src/librustc_mir/transform/check_unsafety.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
132132
}
133133
&AggregateKind::Closure(def_id, _) | &AggregateKind::Generator(def_id, _, _) => {
134134
let UnsafetyCheckResult { violations, unsafe_blocks } =
135-
self.tcx.unsafety_check_result(def_id);
135+
self.tcx.unsafety_check_result(def_id.expect_local());
136136
self.register_violations(&violations, &unsafe_blocks);
137137
}
138138
},
@@ -485,7 +485,7 @@ fn check_unused_unsafe(
485485
intravisit::Visitor::visit_body(&mut visitor, body);
486486
}
487487

488-
fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult {
488+
fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: LocalDefId) -> UnsafetyCheckResult {
489489
debug!("unsafety_violations({:?})", def_id);
490490

491491
// 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
494494

495495
let param_env = tcx.param_env(def_id);
496496

497-
let id = tcx.hir().as_local_hir_id(def_id.expect_local());
497+
let id = tcx.hir().as_local_hir_id(def_id);
498498
let (const_context, min_const_fn) = match tcx.hir().body_owner_kind(id) {
499499
hir::BodyOwnerKind::Closure => (false, false),
500-
hir::BodyOwnerKind::Fn => (is_const_fn(tcx, def_id), is_min_const_fn(tcx, def_id)),
500+
hir::BodyOwnerKind::Fn => {
501+
(is_const_fn(tcx, def_id.to_def_id()), is_min_const_fn(tcx, def_id.to_def_id()))
502+
}
501503
hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => (true, false),
502504
};
503505
let mut checker = UnsafetyChecker::new(const_context, min_const_fn, body, tcx, param_env);
504506
checker.visit_body(&body);
505507

506-
check_unused_unsafe(
507-
tcx,
508-
def_id.expect_local(),
509-
&checker.used_unsafe,
510-
&mut checker.inherited_blocks,
511-
);
508+
check_unused_unsafe(tcx, def_id, &checker.used_unsafe, &mut checker.inherited_blocks);
512509
UnsafetyCheckResult {
513510
violations: checker.violations.into(),
514511
unsafe_blocks: checker.inherited_blocks.into(),
@@ -600,7 +597,8 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
600597
return;
601598
}
602599

603-
let UnsafetyCheckResult { violations, unsafe_blocks } = tcx.unsafety_check_result(def_id);
600+
let UnsafetyCheckResult { violations, unsafe_blocks } =
601+
tcx.unsafety_check_result(def_id.expect_local());
604602

605603
for &UnsafetyViolation { source_info, description, details, kind } in violations.iter() {
606604
// Report an error.

src/librustc_mir/transform/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs {
210210

211211
fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> &Steal<Body<'_>> {
212212
// Unsafety check uses the raw mir, so make sure it is run
213-
let _ = tcx.unsafety_check_result(def_id);
213+
let _ = tcx.unsafety_check_result(def_id.expect_local());
214214

215215
let mut body = tcx.mir_built(def_id).steal();
216216

0 commit comments

Comments
 (0)