Skip to content

multiple_unsafe_ops_per_block triggering for format! on nightly #16116

@wmmc88

Description

@wmmc88

Summary

The following code will trigger clippy::multiple_unsafe_ops_per_block on 1.93.0-nightly (2025-11-17 0df64c57843a9612c68d), but not on stable 1.91.1: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=12e538ea37bfbf81674c74f0ec119fff

format! on its own doesn't require unsafe, so I'm unsure what's causing multiple_unsafe_ops_per_block to fire on nightly for format!.

Lint Name

multiple_unsafe_ops_per_block

Reproducer

I tried this code:

#![forbid(clippy::multiple_unsafe_ops_per_block)]

unsafe fn foo() -> u32 {
    0
}

fn main() {
    unsafe{
        let _ = format!("{}", foo());
    }
}

I saw this happen:

    Checking playground v0.0.1 (/playground)
error: this `unsafe` block contains 2 unsafe operations, expected only one
  --> src/main.rs:8:5
   |
 8 | /     unsafe{
 9 | |         let _ = format!("{}", foo());
10 | |     }
   | |_____^
   |
note: unsafe function call occurs here
  --> src/main.rs:9:31
   |
 9 |         let _ = format!("{}", foo());
   |                               ^^^^^
note: unsafe function call occurs here
  --> src/main.rs:9:17
   |
 9 |         let _ = format!("{}", foo());
   |                 ^^^^^^^^^^^^^^^^^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_unsafe_ops_per_block
note: the lint level is defined here
  --> src/main.rs:1:11
   |
 1 | #![forbid(clippy::multiple_unsafe_ops_per_block)]
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `playground` (bin "playground") due to 1 previous error

I expected to see this happen: successful clippy run

Version

Nightly channel Build using the Nightly version: 1.93.0-nightly (2025-11-17 0df64c57843a9612c68d)

Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions