Skip to content

unused_unsafe false negative in closures in unsafe functions #88260

Closed
@LeSeulArtichaut

Description

@LeSeulArtichaut

Code

I tried this code:

pub unsafe fn unsf() {}

pub unsafe fn foo() {
    let _ = || unsafe { unsf() };
}

I expected to see this happen: compiler lints about the unnecessary unsafe block

Instead, this happened: code compiles without warnings

Version it worked on

It most recently worked on: Rust 1.51.

warning: unnecessary `unsafe` block
 --> <source>:4:16
  |
3 | pub unsafe fn foo() {
  | ------------------- because it's nested under this `unsafe` fn
4 |     let _ = || unsafe { unsf() };
  |                ^^^^^^ unnecessary `unsafe` block
  |
  = note: `#[warn(unused_unsafe)]` on by default

Version with regression

rustc --version --verbose:

rustc 1.56.0-nightly (af140757b 2021-08-22)
binary: rustc
commit-hash: af140757b4cb1a60d107c690720311ba8e06e7de
commit-date: 2021-08-22
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 13.0.0

@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.fixed-by-thir-unsafeck`-Z thir-unsafeck` handles this correctly.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions