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

Error output for mismatched types with a 1-ary tuple could hint to add a missing comma #86100

Closed
asquared31415 opened this issue Jun 7, 2021 · 0 comments · Fixed by #86116
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@asquared31415
Copy link
Contributor

Type mismatch errors with a 1-tuple and a single value wrapped in parentheses could be improved.

let _t: (u8,) = (1);

Playground link with a few other examples

The current output is:

warning: unnecessary parentheses around assigned value
 --> src/main.rs:2:21
  |
2 |     let _t: (u8,) = (1);
  |                     ^^^ help: remove these parentheses
  |
  = note: `#[warn(unused_parens)]` on by default

error[E0308]: mismatched types
 --> src/main.rs:2:21
  |
2 |     let _t: (u8,) = (1);
  |             -----   ^^^ expected tuple, found integer
  |             |
  |             expected due to this
  |
  = note: expected tuple `(u8,)`
              found type `{integer}`

Ideally the E0308 mismatched types error could have a hint when the type of the value and the type of the element in the 1-tuple match that is something along the lines of

help: a tuple with one element needs a comma
    let _t: (u8,) = (1,);
                      ^

I believe that this could improve newcomers' experience by highlighting the difference in the types, especially when the type is inferred like in some of the other playground examples, and explaining the syntax to create a tuple.

Inspired by #86019

@rustbot label +D-papercut +D-newcomer-roadblock

@asquared31415 asquared31415 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 7, 2021
@rustbot rustbot added D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. labels Jun 7, 2021
@bors bors closed this as completed in dddebf9 Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
2 participants