Skip to content

Commit e3d27ec

Browse files
Add explanation about taking the minimum of the two lints
1 parent 4a538d3 commit e3d27ec

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/librustc_mir/transform/check_unsafety.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,17 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
726726
},
727727
),
728728
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`).
729740
let lint = if tcx.lint_level_at_node(SAFE_PACKED_BORROWS, lint_root).0
730741
<= tcx.lint_level_at_node(UNSAFE_OP_IN_UNSAFE_FN, lint_root).0
731742
{

0 commit comments

Comments
 (0)