rust-lang / rust-lang/rust-clippy

New lint: `empty_expect` - detect `.expect("")` with empty message

Open
#16,764 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.