File tree 2 files changed +25
-3
lines changed
compiler/rustc_parse/src/parser
2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -1788,7 +1788,23 @@ impl<'a> Parser<'a> {
1788
1788
}
1789
1789
}
1790
1790
} 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
1792
1808
} ;
1793
1809
return Err ( err) ;
1794
1810
}
Original file line number Diff line number Diff line change 1
1
error: expected identifier, found keyword `let`
2
2
--> $DIR/removed-syntax-field-let.rs:2:5
3
3
|
4
- LL | struct S {
5
- | - while parsing this struct
6
4
LL | let foo: (),
7
5
| ^^^ 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
+ |
8
14
9
15
error: aborting due to previous error
10
16
You can’t perform that action at this time.
0 commit comments