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

Tuple indexing should handle float tokens specially #28257

Closed
chris-morgan opened this issue Sep 5, 2015 · 9 comments
Closed

Tuple indexing should handle float tokens specially #28257

chris-morgan opened this issue Sep 5, 2015 · 9 comments
Labels
T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@chris-morgan
Copy link
Member

tuple.0.0 tokenises as [Ident("tuple"), Dot, Float("0.0")]. At present it produces an “unexpected token” error with a help message along the lines of “try parenthesizing the first index; e.g., (tuple.0).0”.

This is silly. We should just special-case float literals of the form /\d+.\d+/ and understand them sensibly—that the original one be treated as [Ident("tuple"), Dot, Int("0"), Dot, Int("0")]. It’s not as though there’s any ambiguity (that I see, anyway), and it’s much nicer to handle something automatically where there is no ambiguity and the meaning is perfectly clear, rather than producing a helpful error message.

There’s precedent for this approach to things in the handling of the && token, where the expression &&foo and the pattern &&foo are both treated as two & tokens rather than as a single && token.

@huonw
Copy link
Member

huonw commented Sep 5, 2015

NB. this behaviour was explicitly discussed as part of rust-lang/rfcs#184 that designed this feature.

@steveklabnik
Copy link
Member

/cc @rust-lang/lang, but yes, I thought this was explicitly decided against in the RFC

@chris-morgan
Copy link
Member Author

(I guess #20287 and #23694 are the same as this; I just didn’t find either of them in my searching.)

I really think we should reconsider this. I don’t get the feel that it was so much explicitly decided against in the RFC as that one or possibly two people felt uncomfortable with it and so it was removed from the RFC as the easiest thing to do.

I really don’t see any reason for not doing this; it’s not difficult to do, and it makes things do what people expect, as is evidenced by the very way in which the special help message on the error is done. Can anyone present an argument for not doing it? @nikomatsakis, as you preferred not to change the lexer thus at that time a year ago?

@liigo
Copy link
Contributor

liigo commented Sep 7, 2015 via email

@nikomatsakis
Copy link
Contributor

On Sat, Sep 05, 2015 at 02:01:02PM -0700, Steve Klabnik wrote:

/cc @rust-lang/lang, but yes, I thought this was explicitly decided against in the RFC

It was, though I've been bit by it a few times and wondered if we made
the right call from time to time.

@pnkfelix
Copy link
Member

(and @nikomatsakis did even say at that time "we can always add it later" :) )

@hayathms
Copy link

I think Adding it is better
plain chained dot notation for accessing nested tuple is required as it feels more natural.

tuple_of_tuples.1.1.0.3.0.1 -> heart says it should work :) :) :)

@steveklabnik
Copy link
Member

Triage: this was an explicitly made decision in an RFC, and so I'd argue that it needs an RFC to change. Given that and the lack of comments, I'm going to give this one a close.

@steveklabnik steveklabnik added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Mar 24, 2017
@dtolnay
Copy link
Member

dtolnay commented Mar 29, 2020

I put up a fix in #70420. I don't think an RFC is going to be required. If the compiler team is on board with the approach, then the lang team can do FCP on the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants