Static rustc_lint_defs::builtin::UNSAFE_OP_IN_UNSAFE_FN

source ·
pub static UNSAFE_OP_IN_UNSAFE_FN: &Lint
Expand description

The unsafe_op_in_unsafe_fn lint detects unsafe operations in unsafe functions without an explicit unsafe block.



unsafe fn foo() {}

unsafe fn bar() {

fn main() {}



Currently, an unsafe fn allows any unsafe operation within its body. However, this can increase the surface area of code that needs to be scrutinized for proper behavior. The unsafe block provides a convenient way to make it clear exactly which parts of the code are performing unsafe operations. In the future, it is desired to change it so that unsafe operations cannot be performed in an unsafe fn without an unsafe block.

The fix to this is to wrap the unsafe code in an unsafe block.

This lint is “allow” by default on editions up to 2021, from 2024 it is “warn” by default; the plan for increasing severity further is still being considered. See RFC #2585 and issue #71668 for more details.