rust-lang / rust-lang/rust-clippy
New lint: `empty_expect` - detect `.expect("")` with empty message
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Detects calls to .expect("") where the expect message is an empty string literal.
Why
When clippy::unwrap_used is denied, developers sometimes use .expect("") as a workaround — which provides no more context than .unwrap() on panic. The expect message should be meaningful.
Example
// Bad - should lint
let x: Option<i32> = Some(1);
let _ = x.expect("");
let v: Result<i32, &str> = Ok(1);
let _ = v.expect("");
// Good - no lint
let _ = x.expect("value should be present after initialization");
let _ = v.expect("parsing always succeeds for valid input");
Category
style or suspicious
Real-world motivation
In our codebase we deny unwrap_used to enforce better error context. Some developers bypass this by writing .expect(""), which defeats the purpose. Currently there is no Clippy lint to catch this — we resort to grep-based CI checks.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating existing Clippy lint implementations and their UI tests, then inspect how method calls and string literals are checked. Add coverage for .expect("") on both Option and Result, while confirming meaningful non-empty messages do not trigger; done means the new lint is categorized and documented consistently with neighboring lints.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100