rust-lang / rust-lang/rust-clippy

How about a `redundant_ok` lint?

Open
#17,271 2 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

I've noticed a few places in the code with which I work where Ok( and ?) can be removed from the ends of a line without altering system behavior - would it be good to have Clippy flag those?

Advantage

The advantage would be that the code on the page gets to avoid (a small bit of) unnecessary syntactic structural complexity.

Drawbacks

Maybe some folks like seeing the Ok as a visual reminder or cue of "this is an exit point of the current behavior"? Since there's not a return keyword like in other languages? ... but I'm just supposing and speculating about that.

Example
Ok(helper_function_call(4)?)

Could be written as:

helper_function_call(4)
Comparison with existing lints

I had figured that this probably already existed, but it doesn't yet seem to, nor did I find any past issue proposing it.

Additional Context

I'm not aware of any additional context; feel free to inform me about what I am overlooking.

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 lints related to redundant expressions and compare their handling of the Ok(helper_function_call(4)?) example. Determine the intended cases and exceptions, then add coverage showing when the lint should flag code and when it should not.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.