Skip to content

False positive for unused-unsafe #7626

Closed
@cmichi

Description

@cmichi

Lint name: unused-unsafe

I tried this code:

src/lib.rs:

pub extern fn test() {
  unsafe { core::arch::wasm32::unreachable(); }
}

Cargo.toml:

[package]
name = "test"
version = "0.1.0"
edition = "2018"

[lib]
name = "test"
path = "src/lib.rs"
crate-type =["cdylib"]

[dependencies]

I expected to see this happen: No lint error should be reported.

Instead, this happened:

$ cargo clippy --verbose --no-default-features --target wasm32-unknown-unknown -- -D warnings
…
error: unnecessary `unsafe` block
 --> src/lib.rs:2:2                                                                                                                                            
  |                                                                                                                                                            
2 |     unsafe { core::arch::wasm32::unreachable(); }                                                                                                          
  |     ^^^^^^ unnecessary `unsafe` block                                                                                                                      
  |                                                                            
  = note: `-D unused-unsafe` implied by `-D warnings`

The function is marked as unsafe though: https://doc.rust-lang.org/stable/core/arch/wasm32/fn.unreachable.html.

There is also no lint error reported if I switch to rustup override set nightly-2021-08-13.

Meta

Rust version (rustc -Vv):

rustc 1.56.0-nightly (371f3cd3f 2021-09-02)
binary: rustc
commit-hash: 371f3cd3fe523d0b398ed1db1620667c53ba7d02
commit-date: 2021-09-02
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 13.0.0

Metadata

Metadata

Assignees

No one assigned

    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