rust-lang / rust-lang/rust-clippy

New lint: qualified `None` to help make code more readable

Open
#14,523 0 comments 4 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

I'd like to suggest a new lint that checks for naked Nones and asks to qualify them with the inner type of the Option.

Advantage
  • Code becomes more readable, especially when looked at without inlay hints.
  • Might warn against unexpected type changes, that a naked None wouldn't catch.
Drawbacks
  • This may not be for everyone, so I suggest "restricted" as the target lint group.
Example
fn myfunc(s: Option<String>) { .. }
myfunc(None);

Could be written as:

myfunc(None::<String>);

The lint should also ask to rewrite instances of Option::<T>::None as None::<T>.

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 from the issue's examples: naked None in an Option call should be qualified, and Option::::None should be rewritten as None::. Check how both forms should be diagnosed and tested, including the restricted lint group; done when the lint consistently identifies both cases and offers the requested rewrites.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.