@@ -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