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

in which .. is suggested for erroneous ... in struct field patterns #46763

Conversation

zackmdavis
Copy link
Member

Resolves #46718. Supersedes #46721.

r? @petrochenkov

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Dec 16, 2017

📌 Commit d40197c has been approved by petrochenkov

@petrochenkov
Copy link
Contributor

petrochenkov commented Dec 16, 2017

@zackmdavis @estebank
This issue, like many others, fits into more general pattern of "confusable tokens".
Each token T has set of tokens that are likely to be used instead of it by mistake {U1, U2, U3, ...}, either due to similarity to other languages, or keyboard layout, or other reasons.
In all contexts where we expect T, don't expect Ui and actually see Ui we should accept it, report a non-fatal error recommending T instead, and continue parsing.

This PR is a very typical diagnostic PR adding an ad hoc custom error for a single token in a single context ignoring the larger picture.
For example, the situation ".. but not ..." can arise in other contexts, like expressions + the "confusable" relation is symmetric, so we can also recommend ... in situations "... but not ..", e.g. variadic functions in FFI.

It would be more useful to fix this generically, e.g. to add something like fn expect_token(token::DotDot) used in all contexts expecting .. that would check for tokens confusable with .. automatically.
The main problem with doing this generically is that the "don't expect Ui" may be non-trivial and require lookaheads and duplicated logic, but it's probably still possible to come up with some usable interface.

Even without generic approach, fixing all contexts (including symmetry) for a specific pair of tokens (like .. vs ...) would be nice.

@kennytm kennytm added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Dec 16, 2017
@bors
Copy link
Contributor

bors commented Dec 16, 2017

⌛ Testing commit d40197c with merge 3bee2b4...

bors added a commit that referenced this pull request Dec 16, 2017
…_pattern_ellipsis, r=petrochenkov

in which `..` is suggested for erroneous `...` in struct field patterns

Resolves #46718. Supersedes #46721.

r? @petrochenkov
@bors
Copy link
Contributor

bors commented Dec 16, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: petrochenkov
Pushing 3bee2b4 to master...

@bors bors merged commit d40197c into rust-lang:master Dec 16, 2017
@zackmdavis zackmdavis deleted the and_the_case_of_the_erroneous_field_pattern_ellipsis branch January 13, 2018 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants