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

Don't require parentheses when accessing nested tuple #20287

Closed
nstoddard opened this issue Dec 28, 2014 · 5 comments
Closed

Don't require parentheses when accessing nested tuple #20287

nstoddard opened this issue Dec 28, 2014 · 5 comments

Comments

@nstoddard
Copy link

If you have a nested tuple like this:

let a = ((1u8, 2u8), (3u8, 4u8));

You can't access it like this:

println!("{}", a.1.1);

Instead, you have to do this:

println!("{}", (a.1).1);

I can't think of any good reason why the former shouldn't be allowed. Maybe rustc is parsing it as the number 1.1? It seems like it shouldn't be hard to fix, since the compiler is already able to suggest adding the parentheses.

@sinistersnare
Copy link
Contributor

relevant part of RFC

@ftxqxd
Copy link
Contributor

ftxqxd commented Dec 29, 2014

The RFC originally allowed indexing nested tuples without parentheses, but the team decided that they didn’t want to contort the grammar to support that. FWIW, I recently discovered that parentheses aren’t actually required: you can use whitespace instead; e.g., foo.1 .1. It’s not much of an improvement, though.

@nstoddard
Copy link
Author

Okay, feel free to close this if the team thinks it's not worth implementing.

@sffc
Copy link

sffc commented Jul 25, 2020

Not high-priority, but it would still be nice to fix this syntax and avoid the search on how to work around it.

@petrochenkov
Copy link
Contributor

@sffc
This was actually implemented recently - #71322.

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

No branches or pull requests

6 participants