Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unused_unsafe false negative in closures in unsafe functions #88260

Closed
LeSeulArtichaut opened this issue Aug 23, 2021 · 1 comment · Fixed by #93678
Closed

unused_unsafe false negative in closures in unsafe functions #88260

LeSeulArtichaut opened this issue Aug 23, 2021 · 1 comment · Fixed by #93678
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. fixed-by-thir-unsafeck `-Z thir-unsafeck` handles this correctly. P-low Low priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@LeSeulArtichaut
Copy link
Contributor

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

@LeSeulArtichaut LeSeulArtichaut added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Aug 23, 2021
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-untriaged Untriaged performance or correctness regression. labels Aug 23, 2021
@LeSeulArtichaut LeSeulArtichaut added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 23, 2021
@oli-obk oli-obk added the fixed-by-thir-unsafeck `-Z thir-unsafeck` handles this correctly. label Aug 23, 2021
@apiraino
Copy link
Contributor

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

@rustbot label -I-prioritize +P-low

@rustbot rustbot added P-low Low priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 26, 2021
Manishearth added a commit to Manishearth/rust that referenced this issue Oct 4, 2021
…block-std, r=dtolnay

Remove unnecessary unsafe block in `process_unix`

Because it's nested under this unsafe fn!

This block isn't detected as unnecessary because of a bug in the compiler: rust-lang#88260.
Manishearth added a commit to Manishearth/rust that referenced this issue Oct 4, 2021
…block-std, r=dtolnay

Remove unnecessary unsafe block in `process_unix`

Because it's nested under this unsafe fn!

This block isn't detected as unnecessary because of a bug in the compiler: rust-lang#88260.
@bors bors closed this as completed in 45e2c28 Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. fixed-by-thir-unsafeck `-Z thir-unsafeck` handles this correctly. P-low Low priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants