Skip to content

Commit 01a2246

Browse files
authored
Rollup merge of #101789 - gimbles:let, r=estebank
`let`'s not needed in struct field definitions Fixes #101683
2 parents d8d01e3 + 6071b4b commit 01a2246

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

compiler/rustc_parse/src/parser/item.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,23 @@ impl<'a> Parser<'a> {
17881788
}
17891789
}
17901790
} else {
1791-
self.expected_ident_found()
1791+
let mut err = self.expected_ident_found();
1792+
if let Some((ident, _)) = self.token.ident() && ident.as_str() == "let" {
1793+
self.bump(); // `let`
1794+
let span = self.prev_token.span.until(self.token.span);
1795+
err.span_suggestion(
1796+
span,
1797+
"remove the let, the `let` keyword is not allowed in struct field definitions",
1798+
String::new(),
1799+
Applicability::MachineApplicable,
1800+
);
1801+
err.note("the `let` keyword is not allowed in `struct` fields");
1802+
err.note("see <https://doc.rust-lang.org/book/ch05-01-defining-structs.html> for more information");
1803+
err.emit();
1804+
self.bump();
1805+
return Ok(ident);
1806+
}
1807+
err
17921808
};
17931809
return Err(err);
17941810
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
error: expected identifier, found keyword `let`
22
--> $DIR/removed-syntax-field-let.rs:2:5
33
|
4-
LL | struct S {
5-
| - while parsing this struct
64
LL | let foo: (),
75
| ^^^ expected identifier, found keyword
6+
|
7+
= note: the `let` keyword is not allowed in `struct` fields
8+
= note: see <https://doc.rust-lang.org/book/ch05-01-defining-structs.html> for more information
9+
help: remove the let, the `let` keyword is not allowed in struct field definitions
10+
|
11+
LL - let foo: (),
12+
LL + foo: (),
13+
|
814

915
error: aborting due to previous error
1016

0 commit comments

Comments
 (0)