Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecssary parenthesis lint #10557

Open
bilelmoussaoui opened this issue Mar 27, 2023 · 2 comments
Open

Unnecssary parenthesis lint #10557

bilelmoussaoui opened this issue Mar 27, 2023 · 2 comments
Assignees
Labels
A-lint Area: New lints

Comments

@bilelmoussaoui
Copy link

bilelmoussaoui commented Mar 27, 2023

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);
}
@bilelmoussaoui bilelmoussaoui added the A-lint Area: New lints label Mar 27, 2023
@blyxyas blyxyas removed their assignment Mar 27, 2023
@asquared31415
Copy link
Contributor

asquared31415 commented Mar 28, 2023

rustc has an unused_parens lint, this might be a shortcoming of that lint. notably some_fn((x)) and let _ = (x); do have a warning triggered, so it might be something to do with being part of the as cast there?

Edit: it is not always possible to remove the parens in an as cast, for example removing the parentheses in (1 + 2) as f32 makes it stop compiling, since 1 + 2 as f32 parses as 1 + (2 as f32), which is {integer} + f32 and so presumably rustc doesn't attempt to check unused parens in this case, to be on the safe side.

@KisaragiEffective
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
4 participants