rust-lang / rust-lang/rust-clippy

Warn on any panic code like `unwrap`, `expect`, `assert`, `todo`, ...

Open
#12,754 2 comments 3 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

When a library tries to be as "clean" as possible, it may want to prevent any accidental panics. Panics could be caused by many different calls. Clippy offers unwrap_used, todo, and some other lints, but there is no single lint that will catch any panic-producing calls. Granted that it is impossible to catch all such cases, but having a common lint that will grow as more panic-y functions are added to stdlib may offer a more stable solution.

Advantage
  • consolidates all panic-catching lints under one name, preventing user from accidentally missing some
  • as more panic-producing functions are added to stdlib, this lint will include them too
  • clearly indicates intention of "no panic" goal of the lib
Drawbacks

some panics are hard to catch, e.g. arithmetic wrapping (or maybe it should be caught too somehow?)

Example
result.unwrap()

Could be written as:

if Ok(v) = result { ... } else { ... }

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

Review the existing unwrap_used and todo lints first, along with the issue's example of result.unwrap(). Define the intended set of panic-producing calls and how arithmetic wrapping is handled; done means one stable lint consolidates the relevant panic-catching behavior and can grow as standard-library cases are added.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.