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

undocumented_unsafe_blocks doesn't recognise safety comments before consts in impl blocks #12720

Open
Spartan2909 opened this issue Apr 27, 2024 · 1 comment · May be fixed by #12672
Open

undocumented_unsafe_blocks doesn't recognise safety comments before consts in impl blocks #12720

Spartan2909 opened this issue Apr 27, 2024 · 1 comment · May be fixed by #12672
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

@Spartan2909
Copy link

Summary

undocumented_unsafe_blocks lints on documented unsafe blocks that constitute the body of a const in an impl block.

I get the expected behaviour if I put both the unsafe block and the safety comment into a block expression, or if I remove the item from the impl block.

Lint Name

undocumented_unsafe_blocks

Reproducer

I tried this code:

pub struct SourceId(NonZeroU64);

impl SourceId {
    // SAFETY: 1 is not 0.
    const DUMMY: SourceId = unsafe { SourceId(NonZeroU64::new_unchecked(1)) };
}

I saw this happen:

error: unsafe block missing a safety comment
  --> continuate-error\src\lib.rs:20:29
   |
20 |     const DUMMY: SourceId = unsafe { SourceId(NonZeroU64::new_unchecked(1)) };
   |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: consider adding a safety comment on the preceding line
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks
   = note: requested on the command line with `-D clippy::undocumented-unsafe-blocks`

I expected to see this happen:

No output.

Version

rustc 1.79.0-nightly (ef8b9dcf2 2024-04-24)
binary: rustc
commit-hash: ef8b9dcf23700f2e2265317611460d3a65c19eff
commit-date: 2024-04-24
host: x86_64-pc-windows-msvc
release: 1.79.0-nightly
LLVM version: 18.1.4

Additional Labels

No response

@Spartan2909 Spartan2909 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 Apr 27, 2024
@J-ZhengLi
Copy link
Member

duplicate of #11709 , which will hopefully be fixed after #12672 land~

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.

2 participants