Skip to content

unsafe_op_in_unsafe_fn warning in Rust edition 2024 #3147

Open
@jmjoy

Description

@jmjoy

The unsafe_op_in_unsafe_fn lint now warns by default. This warning detects calls to unsafe operations in unsafe functions without an explicit unsafe block.

warning[E0133]: dereference of raw pointer is unsafe and requires unsafe block
  --> /origin/home/jmjoy/workspace/rust/phper/target/debug/build/phper-sys-ef5a7a32f49c54c5/out/php_bindings.rs:39:20
   |
39 |         let byte = *(core::ptr::addr_of!((*this).storage) as *const u8).offset(byte_index as isize);
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ dereference of raw pointer
   |
   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/unsafe-op-in-unsafe-fn.html>
   = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
note: an unsafe function restricts its caller, but its body is safe by default
  --> /origin/home/jmjoy/workspace/rust/phper/target/debug/build/phper-sys-ef5a7a32f49c54c5/out/php_bindings.rs:36:5
   |
36 |     pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: `#[warn(unsafe_op_in_unsafe_fn)]` on by default

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions