Skip to content

undocumented_unsafe_blocks doesn't detect safety comment above associated constant #11709

New issue

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

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

Already on GitHub? # to your account

Closed
ketsuban opened this issue Oct 24, 2023 · 2 comments · Fixed by #13888
Closed

undocumented_unsafe_blocks doesn't detect safety comment above associated constant #11709

ketsuban opened this issue Oct 24, 2023 · 2 comments · Fixed by #13888
Assignees
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

@ketsuban
Copy link

ketsuban commented Oct 24, 2023

Summary

I make use of the voladdress crate which uses a pattern of "unsafe construction, safe use", but when I put a VolAddress in a constant clippy doesn't detect the safety comment I add above it.

Reproducer

I tried this code:

#![warn(clippy::undocumented_unsafe_block)]

use voladdress::{Safe, VolAddress};

struct Control(u16);

impl Control {
    // SAFETY: this is safe
    const REGISTER: VolAddress<Self, Safe, Safe> = unsafe { VolAddress::new(0x0400_0204) };
}

I expected to see this happen:
no clippy warning

Instead, this happened:
a clippy warning

Version

rustc 1.75.0-nightly (1c05d50c8 2023-10-21)
binary: rustc
commit-hash: 1c05d50c8403c56d9a8b6fb871f15aaa26fb5d07
commit-date: 2023-10-21
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.3

Additional Labels

No response

@ketsuban ketsuban added the C-bug Category: Clippy is not doing the correct thing label Oct 24, 2023
@J-ZhengLi
Copy link
Member

@rustbot claim

@profetia
Copy link
Contributor

@rustbot claim

@rustbot rustbot assigned profetia and unassigned J-ZhengLi Dec 28, 2024
profetia added a commit to profetia/rust-clippy that referenced this issue Feb 17, 2025
profetia added a commit to profetia/rust-clippy that referenced this issue Feb 23, 2025
profetia added a commit to profetia/rust-clippy that referenced this issue Mar 1, 2025
github-merge-queue bot pushed a commit that referenced this issue Mar 1, 2025
fixes #11709

Continuation of #12672. r? @Alexendoo if you don't mind?

changelog: [`undocumented_unsafe_blocks`] fix FP on trait/impl items
# for free to join this conversation on GitHub. Already have an account? # 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
3 participants