@@ -579,8 +579,8 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: LocalDefId) -> UnsafetyCheckRe
579
579
}
580
580
}
581
581
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) ;
584
584
585
585
tcx. struct_span_lint_hir ( SAFE_PACKED_BORROWS , lint_hir_id, tcx. def_span ( def_id) , |lint| {
586
586
// 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> {
659
659
}
660
660
}
661
661
662
- pub fn check_unsafety ( tcx : TyCtxt < ' _ > , def_id : DefId ) {
662
+ pub fn check_unsafety ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
663
663
debug ! ( "check_unsafety({:?})" , def_id) ;
664
664
665
665
// closures are handled by their parent fn.
666
- if tcx. is_closure ( def_id) {
666
+ if tcx. is_closure ( def_id. to_def_id ( ) ) {
667
667
return ;
668
668
}
669
669
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) ;
672
671
673
672
for & UnsafetyViolation { source_info, lint_root, description, details, kind } in
674
673
violations. iter ( )
@@ -693,8 +692,10 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
693
692
. emit ( ) ;
694
693
}
695
694
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 ( ) ) ;
698
699
} else {
699
700
tcx. struct_span_lint_hir (
700
701
SAFE_PACKED_BORROWS ,
0 commit comments