Skip to content

syntax: Extra diagnostics for _ used in an identifier position #32506

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

Merged
merged 1 commit into from
Mar 31, 2016

Conversation

petrochenkov
Copy link
Contributor

Closes #32501

@rust-highfive
Copy link
Contributor

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

let mut err = self.fatal(&format!("expected identifier, found `{}`",
self.this_token_to_string()));
if self.token == token::Underscore {
err.fileline_note(self.span, "`_` is not an identifier but a wildcard pattern \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the reference, a "wildcard pattern" is .. (two dots) which can match with multiple data fields, as in

struct S(i32, i32);
let S(..) = S(0, 1);

The underscore seems to be called a "placeholder".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, the compiler uses "wildcard", wikipedia uses it too and that part of the reference looks ancient and not well-maintained.

@hanna-kruppe
Copy link
Contributor

👍 while the referenced issue is a bit artificial, people are regularly confused by _ being special. Anything which highlights that it's not an identifier will help with that.

@petrochenkov
Copy link
Contributor Author

r? @Manishearth

let mut err = self.fatal(&format!("expected identifier, found `{}`",
self.this_token_to_string()));
if self.token == token::Underscore {
err.fileline_note(self.span, "`_` is a wildcard pattern and not an identifier");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "pattern, not an" instead of "pattern and not an"

@Manishearth
Copy link
Member

@bors delegate+

r=me once you fix the nit. (comment @bors r=Manishearth when you do)

@bors
Copy link
Collaborator

bors commented Mar 30, 2016

📌 Commit 1c08cb1 has been approved by `Manishearth``

@bors
Copy link
Collaborator

bors commented Mar 30, 2016

✌️ @petrochenkov can now approve this pull request

@Manishearth
Copy link
Member

@bors r-

ugh, it picked up the r=manishearth from my comment

@petrochenkov
Copy link
Contributor Author

@bors r=Manishearth

@bors
Copy link
Collaborator

bors commented Mar 31, 2016

📌 Commit 1cbdf4e has been approved by Manishearth

bors added a commit that referenced this pull request Mar 31, 2016
syntax: Extra diagnostics for `_` used in an identifier position

Closes #32501
@bors
Copy link
Collaborator

bors commented Mar 31, 2016

⌛ Testing commit 1cbdf4e with merge e1195c2...

@bors bors merged commit 1cbdf4e into rust-lang:master Mar 31, 2016
@petrochenkov petrochenkov deleted the use branch September 21, 2016 19:54
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.

7 participants