rust-lang / rust-lang/rust-clippy

`undocumented_unsafe_blocks` doesn't honour `#[allow(clippy::all)]`

Open
#14,519 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Summary

I'm using the undocumented_unsafe_blocks lint in my Cargo.toml, but want to exclude a certain module from any lints, as it's auto generated by using #[allow(clippy::all)].

The lint still triggers.

P.S.: Thanks for your great presentation at Rustikon @llogiq, where I learned about this lint ❤ !

Lint Name

No response

Reproducer

I tried this code:

# Cargo.toml
[package]
name = "foo"
version = "0.1.0"
edition = "2021"

[dependencies]

[lints.clippy]
undocumented_unsafe_blocks = "deny"
// src/lib.rs
#![allow(clippy::all)]
pub fn add(left: u64, right: u64) -> u64 {
    unsafe { foo(left, right) }
}

unsafe fn foo(left: u64, right: u64) -> u64 {
    left + right
}

I saw this happen:

error: unsafe block missing a safety comment
 --> src/lib.rs:3:5
  |
3 |     unsafe { foo(left, right) }
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = 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`

error: could not compile `foo` (lib) due to 1 previous error

I expected to see this happen:
With this diff, clippy ignores the lint as expected:

#![allow(clippy::all, clippy::undocumented_unsafe_blocks)]
Version
rustc 1.85.1 (4eb161250 2025-03-15)
binary: rustc
commit-hash: 4eb161250e340c8f48f66e2b929ef4a5bed7c181
commit-date: 2025-03-15
host: aarch64-apple-darwin
release: 1.85.1
LLVM version: 19.1.7
Additional Labels

No response

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

Reproduce the behavior using the Cargo.toml and src/lib.rs examples, then inspect the undocumented_unsafe_blocks lint and how clippy::all is applied. Done means the lint is suppressed by #[allow(clippy::all)] and the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.