@@ -1715,6 +1715,7 @@ impl<'a> Parser<'a> {
17151715 fn parse_field_ident ( & mut self , adt_ty : & str , lo : Span ) -> PResult < ' a , Ident > {
17161716 let ( ident, is_raw) = self . ident_or_err ( ) ?;
17171717 if !is_raw && ident. is_reserved ( ) {
1718+ let snapshot = self . create_snapshot_for_diagnostic ( ) ;
17181719 let err = if self . check_fn_front_matter ( false ) {
17191720 let inherited_vis = Visibility {
17201721 span : rustc_span:: DUMMY_SP ,
@@ -1735,6 +1736,22 @@ impl<'a> Parser<'a> {
17351736 err. help ( "unlike in C++, Java, and C#, functions are declared in `impl` blocks" ) ;
17361737 err. help ( "see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information" ) ;
17371738 err
1739+ } else if self . eat_keyword ( kw:: Struct ) {
1740+ match self . parse_item_struct ( ) {
1741+ Ok ( ( ident, _) ) => {
1742+ let mut err = self . struct_span_err (
1743+ lo. with_hi ( ident. span . hi ( ) ) ,
1744+ & format ! ( "structs are not allowed in {adt_ty} definitions" ) ,
1745+ ) ;
1746+ err. help ( "consider creating a new `struct` definition instead of nesting" ) ;
1747+ err
1748+ }
1749+ Err ( err) => {
1750+ err. cancel ( ) ;
1751+ self . restore_snapshot ( snapshot) ;
1752+ self . expected_ident_found ( )
1753+ }
1754+ }
17381755 } else {
17391756 self . expected_ident_found ( )
17401757 } ;
0 commit comments