Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 794c7f4

Browse files
Rollup merge of rust-lang#101789 - gimbles:let, r=estebank
`let`'s not needed in struct field definitions Fixes rust-lang#101683
2 parents 8921e6b + 6071b4b commit 794c7f4

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

‎compiler/rustc_parse/src/parser/item.rs‎

Lines changed: 17 additions & 1 deletion
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
}
Lines changed: 8 additions & 2 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /