Skip to content

Incorrect unnecessary parenthesis inside attribute parameters  #104457

@akrieger

Description

@akrieger

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=5b455db4401f5a5f2bd6bec013fab8de

use clap::{Parser};

#[derive(Debug, Parser)]
pub struct Args {
    #[arg(short, long, value_name="ingredients.txt", default_value_t=("ingredients.rs".to_owned()))]
    ingredients: String,
}

The current output is:

warning: unnecessary parentheses around assigned value
 --> src/lib.rs:5:70
  |
5 |     #[arg(short, long, value_name="ingredients.txt", default_value_t=("ingredients.rs".to_owned()))]
  |                                                                      ^                           ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
5 -     #[arg(short, long, value_name="ingredients.txt", default_value_t=("ingredients.rs".to_owned()))]
5 +     #[arg(short, long, value_name="ingredients.txt", default_value_t="ingredients.rs".to_owned())]
  |

However removing the parenthesis results in

error: expected `,`
 --> src/lib.rs:5:86
  |
5 |     #[arg(short, long, value_name="ingredients.txt", default_value_t="ingredients.rs".to_owned())]
  |                                                                                      ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsL-unused_parensLint: unused_parensT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions