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

#[allow(unsafe_code)] should be allowed after SAFETY: docs #8679

Closed
Jake-Shadle opened this issue Apr 11, 2022 · 1 comment · Fixed by #10986
Closed

#[allow(unsafe_code)] should be allowed after SAFETY: docs #8679

Jake-Shadle opened this issue Apr 11, 2022 · 1 comment · Fixed by #10986
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@Jake-Shadle
Copy link

Jake-Shadle commented Apr 11, 2022

Summary

PR #8450 changed it so that nothing can appear between the SAFETY: comment and the unsafe block it is documenting, while the intention behind this change is good, I think it might be too aggressive in the specific case of using a #[allow(unsafe_code)] on the same unsafe block being documented.

Reproducer

I tried this code:

// SAFETY: Blah blah blah safety documention
#[allow(unsafe_code)]
unsafe {
    // code goes here
}

I expected to see this happen:

No lint is triggered, the safety documentation applies to the immediately following unsafe block that has one more more attributes on it.

Instead, this happened:

error: unsafe block missing a safety comment

= note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings`
= 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

Moving #[allow(unsafe_code)] up above the SAFETY comment no longer triggers the lint, but IMO this is a regression in readability and could lead users to actually increase the scope of an #[allow(unsafe_code)] rather than having it scoped as tightly as possible.

Version

rustc 1.62.0-nightly (1f7fb6413 2022-04-10)
binary: rustc
commit-hash: 1f7fb6413d6d6c0c929b223e478e44c3db991b03
commit-date: 2022-04-10
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.0

Additional Labels

No response

@Jake-Shadle Jake-Shadle added the C-bug Category: Clippy is not doing the correct thing label Apr 11, 2022
@Centri3
Copy link
Member

Centri3 commented Jun 5, 2023

Considering #10832 is being worked on, I think this is reasonable as well. @rustbot claim

bors added a commit that referenced this issue Jun 20, 2023
Allow safety comment above attributes

Closes #8679

changelog: Enhancement: [`undocumented_safety_block`]: Added `accept-comment-above-attributes` configuration.
@bors bors closed this as completed in 8fd021f Jun 20, 2023
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants