rust-lang / rust-lang/rust-clippy

Unnecssary parenthesis lint

Open
#10,557 3 comments 2 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

Currently, if the code contains unnecessary parenthesis, clippy doesn't warn the user about it. It would be nice if there was some new lint to detect these cases and warn the user about them.

Lint Name

No response

Category

style

Advantage
  • Remove unnecessary parenthesis in the code
Drawbacks

No response

Example
fn new_rect(x: f64, y: f64, width: f64, height: f64) {
    println!("I am a rectangle ({x},{y}) ({width}, {height})");
}

fn main() {
    let x = 0f32;
    let y = 0f32;
    let width = 100f32;
    let height = 100f32;

    new_rect((x) as f64, (y) as f64, (width) as f64, (height) as f64);
}

Could be written as:

fn new_rect(x: f64, y: f64, width: f64, height: f64) {
    println!("I am a rectangle ({x},{y}) ({width}, {height})");
}

fn main() {
    let x = 0f32;
    let y = 0f32;
    let width = 100f32;
    let height = 100f32;

    new_rect(x as f64, y as f64, width as f64, height as f64);
}

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 Rust Clippy style-lint implementations and their tests, then compare them with the unnecessary-parentheses example in the issue. Done means the new lint warns on the shown redundant parentheses while leaving the equivalent simplified code valid.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.