Skip to content

Commit

Permalink
Rollup merge of rust-lang#101789 - gimbles:let, r=estebank
Browse files Browse the repository at this point in the history
`let`'s not needed in struct field definitions

Fixes rust-lang#101683
  • Loading branch information
Dylan-DPC committed Oct 10, 2022
2 parents 8921e6b + 6071b4b commit 794c7f4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
18 changes: 17 additions & 1 deletion compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 8 additions & 2 deletions src/test/ui/parser/removed-syntax-field-let.stderr
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

0 comments on commit 794c7f4

Please sign in to comment.