Open
Description
Summary
I have some public functions in a public struct which make use of checked, infallible .unwrap()
s, which clippy correctly warned about missing # Panics
docs, but when adding #[expect(clippy::missing_panics_doc)]
above the .unwrap()
line, as suggested in the website, it still complained about missing # Panics
section on the same line and additionally about a unfulfilled
expect
.
In case the website changes, here is what i reference:
Individual panics within a function can be ignored with #[expect] or #[allow]:
pub fn will_not_panic(x: usize) { #[expect(clippy::missing_panics_doc, reason = "infallible")] let y = NonZeroUsize::new(1).unwrap(); // If any panics are added in the future the lint will still catch them }
Lint Name
clippy::missing_panics_doc
Reproducer
I tried this code:
#![warn(clippy::missing_panics_doc)]
pub struct T;
impl T {
pub fn some_fn(&self, buf: &[u8]) -> Result<(), ()> {
#[expect(clippy::missing_panics_doc, reason = "test")]
let _ = Self::some_other_fn(buf).unwrap();
Ok(())
}
fn some_other_fn(buf: &[u8]) -> Result<usize, ()> {
const USIZE_LEN: usize = size_of::<usize>();
if buf.len() < USIZE_LEN {
return Err(());
}
let bytes: [u8; USIZE_LEN] = buf[..USIZE_LEN].try_into().unwrap();
Ok(usize::from_ne_bytes(bytes))
}
}
fn main() {
let t = T;
let buf = &10usize.to_ne_bytes();
let _ = t.some_fn(buf);
}
I saw this happen:
warning: docs for function which may panic missing `# Panics` section
--> src/main.rs:6:5
|
6 | pub fn some_fn(&self, buf: &[u8]) -> Result<(), ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: first possible panic found here
--> src/main.rs:8:17
|
8 | let _ = Self::some_other_fn(buf).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(clippy::missing_panics_doc)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: this returns a `Result<_, ()>`
--> src/main.rs:6:5
|
6 | pub fn some_fn(&self, buf: &[u8]) -> Result<(), ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: use a custom `Error` type instead
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#result_unit_err
= note: `#[warn(clippy::result_unit_err)]` on by default
warning: this lint expectation is unfulfilled
--> src/main.rs:7:18
|
7 | #[expect(clippy::missing_panics_doc, reason = "test")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: test
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
warning: `playground` (bin "playground") generated 3 warnings
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.51s
I expected to see this happen:
No warnings anymore.
Version
rustc 1.85.1 (4eb161250 2025-03-15)
binary: rustc
commit-hash: 4eb161250e340c8f48f66e2b929ef4a5bed7c181
commit-date: 2025-03-15
host: x86_64-unknown-linux-gnu
release: 1.85.1
LLVM version: 19.1.7
(but also reproduce-able in the playground with latest stable and nightly)
Additional Labels
No response