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

chore: update enums3.rs addressing extra parentheses usage with tuples #1310

Merged
merged 1 commit into from
Dec 30, 2022

Conversation

HerschelW
Copy link

@HerschelW HerschelW commented Dec 30, 2022

The circumstances surrounding tuples and additional parentheses are in regard to passing an argument to a function. Otherwise, I could not find any reference stating that extra parentheses indicate a tuple.

If I create a tuple such as let tup = (('a',)) I receive the following warning:

unnecessary parentheses around assigned value '#[warn(unused_parens)] on by default'

Furthermore, if I made an attempt to indicate a tuple with a single element by doing double parentheses
let tup = (('a'))
the rustfmt will automatically remove the extra parentheses and assume I meant to indicate a char type. Similar to Python, the comma after the lone element is what will indicate the value being a tuple. ('a',)

@shadows-withal shadows-withal merged commit 69e8a35 into rust-lang:main Dec 30, 2022
@shadows-withal
Copy link
Member

@all-contributors please add @HerschelW for content

@allcontributors
Copy link
Contributor

@diannasoreil

I've put up a pull request to add @HerschelW! 🎉

@vikkio88
Copy link

this breaks the exercise tho, it returns this

Progress: [#########>--------------------------------------------------] 15/94 
⚠️  Compiling of exercises/enums/enums3.rs failed! Please try again. Here's the output:
error[E0061]: this enum variant takes 1 argument but 3 arguments were supplied
  --> exercises/enums/enums3.rs:61:23
   |
61 |         state.process(Message::ChangeColor(255, 0, 255));
   |                       ^^^^^^^^^^^^^^^^^^^^
   |
note: tuple variant defined here
  --> exercises/enums/enums3.rs:6:5
   |
6  |     ChangeColor((u8, u8, u8)),
   |     ^^^^^^^^^^^
help: wrap these arguments in parentheses to construct a tuple
   |
61 |         state.process(Message::ChangeColor((255, 0, 255)));
   |                                            +           +

error: aborting due to previous error

For more information about this error, try `rustc --explain E0061`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants