Skip to content

False postive: warning of unnecessary unsafe block #152374

Description

@zjp-CN

Code

I tried this code:

fn main() {
    let a = unsafe { core::arch::x86_64::__cpuid_count(0, 0) };
    dbg!(a);
}

I expected to see this happen: it compiles without warnings.

Instead, this happened: it compiles with a warning of unnecessary unsafe block

warning: unnecessary `unsafe` block
 --> src/main.rs:2:13
  |
2 |     let a = unsafe { core::arch::x86_64::__cpuid_count(0, 0) };
  |             ^^^^^^ unnecessary `unsafe` block
  |
  = note: `#[warn(unused_unsafe)]` (part of `#[warn(unused)]`) on by default

Version it worked on

Stable channel 1.93.0 doesn't emit that.

Version with regression

Beta channel 1.94.0-beta.2 emits that. (2026-01-25 23a44d3)

Nightly channel 1.95.0-nightly emits that. (2026-02-08 6efa357)

The code can be reproduced on the present plaground: stable vs beta.

Activity

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

    C-discussionCategory: Discussion or questions that doesn't represent real issues.S-has-bisectionStatus: A bisection has been found for this issueT-langRelevant to the language teamT-libs-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions