@@ -370,7 +370,8 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
370
370
violation. kind = UnsafetyViolationKind :: General ;
371
371
}
372
372
}
373
- UnsafetyViolationKind :: UnsafeFn => {
373
+ UnsafetyViolationKind :: UnsafeFn
374
+ | UnsafetyViolationKind :: UnsafeFnBorrowPacked => {
374
375
bug ! ( "`UnsafetyViolationKind::UnsafeFn` in an `Safe` context" )
375
376
}
376
377
}
@@ -385,8 +386,11 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
385
386
for violation in violations {
386
387
let mut violation = * violation;
387
388
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
+ }
390
394
if !self . violations . contains ( & violation) {
391
395
self . violations . push ( violation)
392
396
}
@@ -418,7 +422,8 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
418
422
self . violations . push ( violation)
419
423
}
420
424
}
421
- UnsafetyViolationKind :: UnsafeFn => bug ! (
425
+ UnsafetyViolationKind :: UnsafeFn
426
+ | UnsafetyViolationKind :: UnsafeFnBorrowPacked => bug ! (
422
427
"`UnsafetyViolationKind::UnsafeFn` in an `ExplicitUnsafe` context"
423
428
) ,
424
429
}
@@ -719,13 +724,31 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
719
724
|lint| {
720
725
lint. build ( & format ! (
721
726
"{} is unsafe and requires unsafe block (error E0133)" ,
722
- description
727
+ description,
723
728
) )
724
729
. span_label ( source_info. span , & * description. as_str ( ) )
725
730
. note ( & details. as_str ( ) )
726
731
. emit ( ) ;
727
732
} ,
728
733
) ,
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
+ }
729
752
}
730
753
}
731
754
0 commit comments