Skip to content

unnecessary_safety_comment false positive in _ = unsafe { foo_unsafe() } expression, conflicts with undocumented_unsafe_blocks correct analysis #13039

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

Closed
sandersaares opened this issue Jul 4, 2024 · 0 comments · Fixed by #14371
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@sandersaares
Copy link
Contributor

sandersaares commented Jul 4, 2024

Summary

The unnecessary_safety_comment lint considers a safety comment as being unnecessary if the code is of the shape:

_ = unsafe { foo_unsafe() }

The following alternative shape is correctly identified as requiring a safety comment:

let _ = unsafe { foo_unsafe() }

The undocumented_unsafe_blocks lint expects a safety comment in both cases, so the first case cannot pass Clippy check if both lints are enabled.

Lint Name

unnecessary_safety_comment

Reproducer

unsafe fn foo() -> usize {
    1234
}

#[deny(clippy::unnecessary_safety_comment)]
#[deny(clippy::undocumented_unsafe_blocks)] // For comparison
fn main() {
    // SAFETY: unnecessary_safety_comment incorrectly triggers here
    _ = unsafe { foo() };
}

Version

rustc 1.79.0 (c6bcfe6a60 2024-06-18) (1.79.0-ms-20240619.1+c6bcfe6a60)
binary: rustc
commit-hash: c6bcfe6a6082b23fa084d9690fee241c23ee9d29
commit-date: 2024-06-18
host: x86_64-pc-windows-msvc
release: 1.79.0
LLVM version: 18.1.7

Additional Labels

No response

@sandersaares sandersaares added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jul 4, 2024
github-merge-queue bot pushed a commit that referenced this issue Mar 12, 2025
Closes #13039

changelog: [`unnecessary_safety_comment`]: fix FP on desugared assign
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant