-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
let
's not needed in struct field definitions
#101789
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1788,7 +1788,23 @@ impl<'a> Parser<'a> { | |||||||||
} | ||||||||||
} | ||||||||||
} else { | ||||||||||
self.expected_ident_found() | ||||||||||
let mut err = self.expected_ident_found(); | ||||||||||
if let Some((ident, _)) = self.token.ident() && ident.as_str() == "let" { | ||||||||||
self.bump(); // `let` | ||||||||||
let span = self.prev_token.span.until(self.token.span); | ||||||||||
err.span_suggestion( | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Xiretza this is a good example of a |
||||||||||
span, | ||||||||||
"remove the let, the `let` keyword is not allowed in struct field definitions", | ||||||||||
String::new(), | ||||||||||
Applicability::MachineApplicable, | ||||||||||
); | ||||||||||
err.note("the `let` keyword is not allowed in `struct` fields"); | ||||||||||
err.note("see <https://doc.rust-lang.org/book/ch05-01-defining-structs.html> for more information"); | ||||||||||
err.emit(); | ||||||||||
self.bump(); | ||||||||||
return Ok(ident); | ||||||||||
Comment on lines
+1804
to
+1805
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gimbles for future reference, why is this bumping twice? This should perhaps be:
Suggested change
Otherwise, it seems to me like it's returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Look at the earlier reviews on wonky spans ^^ |
||||||||||
} | ||||||||||
err | ||||||||||
}; | ||||||||||
return Err(err); | ||||||||||
} | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
error: expected identifier, found keyword `let` | ||
--> $DIR/removed-syntax-field-let.rs:2:5 | ||
| | ||
LL | struct S { | ||
| - while parsing this struct | ||
LL | let foo: (), | ||
| ^^^ expected identifier, found keyword | ||
| | ||
= note: the `let` keyword is not allowed in `struct` fields | ||
= note: see <https://doc.rust-lang.org/book/ch05-01-defining-structs.html> for more information | ||
help: remove the let, the `let` keyword is not allowed in struct field definitions | ||
| | ||
LL - let foo: (), | ||
LL + foo: (), | ||
| | ||
|
||
error: aborting due to previous error | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably could've been
self.token.is_keyword(kw::Let)
, seeToken::is_keyword
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, this could've used
Parser::eat_keyword_noexpect
to avoid the bump call belowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, will send an improvement PR later on. 👍🏻