Skip to content

Commit 49b1b4c

Browse files
committed
more LocalDefIds
1 parent 0e9e408 commit 49b1b4c

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

src/librustc_interface/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
838838

839839
sess.time("MIR_effect_checking", || {
840840
for def_id in tcx.body_owners() {
841-
mir::transform::check_unsafety::check_unsafety(tcx, def_id.to_def_id())
841+
mir::transform::check_unsafety::check_unsafety(tcx, def_id)
842842
}
843843
});
844844

src/librustc_middle/query/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,14 @@ rustc_queries! {
386386
storage(ArenaCacheSelector<'tcx>)
387387
}
388388

389-
/// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error
390-
query unsafe_derive_on_repr_packed(_: DefId) -> () {}
389+
/// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error.
390+
///
391+
/// Unsafety checking is executed for each method separately, but we only want
392+
/// to emit this error once per derive. As there are some impls with multiple
393+
/// methods, we use a query for deduplication.
394+
query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
395+
desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
396+
}
391397

392398
/// The signature of functions and closures.
393399
query fn_sig(_: DefId) -> ty::PolyFnSig<'tcx> {}

src/librustc_mir/transform/check_unsafety.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,8 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: LocalDefId) -> UnsafetyCheckRe
579579
}
580580
}
581581

582-
fn unsafe_derive_on_repr_packed(tcx: TyCtxt<'_>, def_id: DefId) {
583-
let lint_hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
582+
fn unsafe_derive_on_repr_packed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
583+
let lint_hir_id = tcx.hir().as_local_hir_id(def_id);
584584

585585
tcx.struct_span_lint_hir(SAFE_PACKED_BORROWS, lint_hir_id, tcx.def_span(def_id), |lint| {
586586
// FIXME: when we make this a hard error, this should have its
@@ -659,16 +659,15 @@ fn builtin_derive_def_id(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
659659
}
660660
}
661661

662-
pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
662+
pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: LocalDefId) {
663663
debug!("check_unsafety({:?})", def_id);
664664

665665
// closures are handled by their parent fn.
666-
if tcx.is_closure(def_id) {
666+
if tcx.is_closure(def_id.to_def_id()) {
667667
return;
668668
}
669669

670-
let UnsafetyCheckResult { violations, unsafe_blocks } =
671-
tcx.unsafety_check_result(def_id.expect_local());
670+
let UnsafetyCheckResult { violations, unsafe_blocks } = tcx.unsafety_check_result(def_id);
672671

673672
for &UnsafetyViolation { source_info, lint_root, description, details, kind } in
674673
violations.iter()
@@ -693,8 +692,10 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
693692
.emit();
694693
}
695694
UnsafetyViolationKind::BorrowPacked => {
696-
if let Some(impl_def_id) = builtin_derive_def_id(tcx, def_id) {
697-
tcx.ensure().unsafe_derive_on_repr_packed(impl_def_id);
695+
if let Some(impl_def_id) = builtin_derive_def_id(tcx, def_id.to_def_id()) {
696+
// If a method is defined in the local crate,
697+
// the impl containing that method should also be.
698+
tcx.ensure().unsafe_derive_on_repr_packed(impl_def_id.expect_local());
698699
} else {
699700
tcx.struct_span_lint_hir(
700701
SAFE_PACKED_BORROWS,

0 commit comments

Comments
 (0)