Skip to content

[Rust] Address lint unsafe_op_in_unsafe_fn since it is now warn by default in 2024 edition #8614

Open
@murtlatif

Description

@murtlatif

The rust 2024 edition release made the following change:

unsafe_op_in_unsafe_fn warning — The unsafe_op_in_unsafe_fn lint now warns by default, requiring explicit unsafe {} blocks in unsafe functions.

Currently, some of the flatbuffers code violates this lint rule. For example, I see tons of these when I cargo check:

warning[E0133]: call to unsafe function `fb::flatbuffers::read_scalar_at` is unsafe and requires unsafe block
   --> target/debug/build/currency-65107e96da7ba87b/out/fb/currency_generated.rs:785:13
    |
785 |     let b = flatbuffers::read_scalar_at::<u16>(buf, loc);
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
    |
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/unsafe-op-in-unsafe-fn.html>
    = note: consult the function's documentation for information on how to avoid undefined behavior
note: an unsafe function restricts its caller, but its body is safe by default
   --> /target/debug/build/currency-65107e96da7ba87b/out/fb/currency_generated.rs:784:3
    |
784 |   unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
    |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: `#[warn(unsafe_op_in_unsafe_fn)]` on by default

Activity

linked a pull request that will close this issue on Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @murtlatif

      Issue actions

        [Rust] Address lint `unsafe_op_in_unsafe_fn` since it is now warn by default in 2024 edition · Issue #8614 · google/flatbuffers