File tree 1 file changed +11
-0
lines changed
src/librustc_mir/transform 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -726,6 +726,17 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
726
726
} ,
727
727
) ,
728
728
UnsafetyViolationKind :: UnsafeFnBorrowPacked => {
729
+ // When `unsafe_op_in_unsafe_fn` is disallowed, the behavior of safe and unsafe functions
730
+ // should be the same in terms of warnings and errors. Therefore, with `#[warn(safe_packed_borrows)]`,
731
+ // a safe packed borrow should emit a warning *but not an error* in an unsafe function,
732
+ // just like in a safe function, even if `unsafe_op_in_unsafe_fn` is `deny`.
733
+ //
734
+ // Also, `#[warn(unsafe_op_in_unsafe_fn)]` can't cause any new errors. Therefore, with
735
+ // `#[deny(safe_packed_borrows)]` and `#[warn(unsafe_op_in_unsafe_fn)]`, a packed borrow
736
+ // should only issue a warning for the sake of backwards compatibility.
737
+ //
738
+ // The solution those 2 expectations is to always take the minimum of both lints.
739
+ // This prevent any new errors (unless both lints are explicitely set to `deny`).
729
740
let lint = if tcx. lint_level_at_node ( SAFE_PACKED_BORROWS , lint_root) . 0
730
741
<= tcx. lint_level_at_node ( UNSAFE_OP_IN_UNSAFE_FN , lint_root) . 0
731
742
{
You can’t perform that action at this time.
0 commit comments