@@ -370,7 +370,8 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
370370 violation. kind = UnsafetyViolationKind :: General ;
371371 }
372372 }
373- UnsafetyViolationKind :: UnsafeFn => {
373+ UnsafetyViolationKind :: UnsafeFn
374+ | UnsafetyViolationKind :: UnsafeFnBorrowPacked => {
374375 bug ! ( "`UnsafetyViolationKind::UnsafeFn` in an `Safe` context" )
375376 }
376377 }
@@ -385,8 +386,11 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
385386 for violation in violations {
386387 let mut violation = * violation;
387388
388- // FIXME(LeSeulArtichaut): what to do with `UnsafetyViolationKind::BorrowPacked`?
389- violation. kind = UnsafetyViolationKind :: UnsafeFn ;
389+ if violation. kind == UnsafetyViolationKind :: BorrowPacked {
390+ violation. kind = UnsafetyViolationKind :: UnsafeFnBorrowPacked ;
391+ } else {
392+ violation. kind = UnsafetyViolationKind :: UnsafeFn ;
393+ }
390394 if !self . violations . contains ( & violation) {
391395 self . violations . push ( violation)
392396 }
@@ -418,7 +422,8 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
418422 self . violations . push ( violation)
419423 }
420424 }
421- UnsafetyViolationKind :: UnsafeFn => bug ! (
425+ UnsafetyViolationKind :: UnsafeFn
426+ | UnsafetyViolationKind :: UnsafeFnBorrowPacked => bug ! (
422427 "`UnsafetyViolationKind::UnsafeFn` in an `ExplicitUnsafe` context"
423428 ) ,
424429 }
@@ -719,13 +724,31 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
719724 |lint| {
720725 lint. build ( & format ! (
721726 "{} is unsafe and requires unsafe block (error E0133)" ,
722- description
727+ description,
723728 ) )
724729 . span_label ( source_info. span , & * description. as_str ( ) )
725730 . note ( & details. as_str ( ) )
726731 . emit ( ) ;
727732 } ,
728733 ) ,
734+ UnsafetyViolationKind :: UnsafeFnBorrowPacked => {
735+ let lint = if tcx. lint_level_at_node ( SAFE_PACKED_BORROWS , lint_root) . 0
736+ <= tcx. lint_level_at_node ( UNSAFE_OP_IN_UNSAFE_FN , lint_root) . 0
737+ {
738+ SAFE_PACKED_BORROWS
739+ } else {
740+ UNSAFE_OP_IN_UNSAFE_FN
741+ } ;
742+ tcx. struct_span_lint_hir ( & lint, lint_root, source_info. span , |lint| {
743+ lint. build ( & format ! (
744+ "{} is unsafe and requires unsafe block (error E0133)" ,
745+ description,
746+ ) )
747+ . span_label ( source_info. span , & * description. as_str ( ) )
748+ . note ( & details. as_str ( ) )
749+ . emit ( ) ;
750+ } )
751+ }
729752 }
730753 }
731754
0 commit comments