rust-lang / rust-lang/rust-clippy

Allow `undocumented_unsafe_block` to detect a safety comment before a block of unsafe impls

Open
#17,280 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-enhancement
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Description

Currently the code block

// SAFETY: RwLockReadGuards act as immutable references, they follow the same rules as them. (see
// core::marker::Sync)
unsafe impl<T: ?Sized + Sync> Sync for RwLockReadGuard<'_, T> {}
unsafe impl<T: ?Sized + Sync> Send for RwLockReadGuard<'_, T> {}

triggers the lint undocumented_unsafe_block for the second unsafe impl.

I would prefer there was an option to allow for the safety comment to count as documenting all the consecutive unsafe impls with a break on an empty line.

Version
rustc 1.98.0-nightly (9e2abe0c6 2026-06-16)
binary: rustc
commit-hash: 9e2abe0c6ab27fcbb95c30695188a75776e2feb1
commit-date: 2026-06-16
host: x86_64-unknown-linux-gnu
release: 1.98.0-nightly
LLVM version: 22.1.7
Additional Labels

@rustbot label +C-enhancement

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the consecutive unsafe impls and the undocumented_unsafe_block lint, then locate the lint's implementation and existing tests in rust-clippy. Done means a safety comment documents consecutive unsafe impls until an empty line, with regression coverage for the reported example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.