diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-10-10 20:47:32 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-10 20:47:32 +0200 |
| commit | 01a224600094e84a3f87ec2d2f3941b4dc8633b7 (patch) | |
| tree | 23800d351adec022990d07e466021b5790d655a6 /compiler | |
| parent | d8d01e32168a24862b9ed2b6a6b7eb0e82fbcfce (diff) | |
| parent | 6071b4b8a64571312017d5eaba01276b90ffe0dc (diff) | |
| download | rust-01a224600094e84a3f87ec2d2f3941b4dc8633b7.tar.gz rust-01a224600094e84a3f87ec2d2f3941b4dc8633b7.zip | |
Rollup merge of #101789 - gimbles:let, r=estebank
`let`'s not needed in struct field definitions Fixes #101683
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 25425fbb2c6..e82044a89c4 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -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( + 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); + } + err }; return Err(err); } |
