Skip to content

Suggest the extra comma for 1-ary tuple when warning about unnecessary parentheses around type #86019

Open
@NicolasDP

Description

@NicolasDP

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

pub type U8 = (u8);

The current output is (1.52.1, 1.53.0-beta.3 and 1.54.0-nightly):

warning: unnecessary parentheses around type
 --> src/lib.rs:1:15
  |
1 | pub type U8 = (u8);
  |               ^^^^ help: remove these parentheses
  |
  = note: `#[warn(unused_parens)]` on by default

warning: 1 warning emitted

Ideally the output should look like:

warning: unnecessary parentheses around type
 --> src/lib.rs:1:15
  |
1 | pub type U8 = (u8);
  |               ^^^^ help: remove these parentheses
  |
  = note: `#[warn(unused_parens)]` on by default
  = note: if you meant to use 1-ary tuple, add an extra comma: `(T,)`
warning: 1 warning emitted

While I appreciate that using 1-ary tuple (T,) may seem odd in most cases it is still part of the language: rust reference. It is also something that the standard library leverages too (generalising trait implementations for 1-ary tuple). Providing this extra note could go a long way to help developers writing generalised implementation of their Trait for n-ary tuples.

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