@@ -1221,7 +1221,7 @@ impl<'a> Parser<'a> {
12211221
12221222 let struct_def = if this. check ( & token:: OpenDelim ( token:: Brace ) ) {
12231223 // Parse a struct variant.
1224- let ( fields, recovered) = this. parse_record_struct_body ( "struct" ) ?;
1224+ let ( fields, recovered) = this. parse_record_struct_body ( "struct" , false ) ?;
12251225 VariantData :: Struct ( fields, recovered)
12261226 } else if this. check ( & token:: OpenDelim ( token:: Paren ) ) {
12271227 VariantData :: Tuple ( this. parse_tuple_struct_body ( ) ?, DUMMY_NODE_ID )
@@ -1275,15 +1275,17 @@ impl<'a> Parser<'a> {
12751275 VariantData :: Unit ( DUMMY_NODE_ID )
12761276 } else {
12771277 // If we see: `struct Foo<T> where T: Copy { ... }`
1278- let ( fields, recovered) = self . parse_record_struct_body ( "struct" ) ?;
1278+ let ( fields, recovered) =
1279+ self . parse_record_struct_body ( "struct" , generics. where_clause . has_where_token ) ?;
12791280 VariantData :: Struct ( fields, recovered)
12801281 }
12811282 // No `where` so: `struct Foo<T>;`
12821283 } else if self . eat ( & token:: Semi ) {
12831284 VariantData :: Unit ( DUMMY_NODE_ID )
12841285 // Record-style struct definition
12851286 } else if self . token == token:: OpenDelim ( token:: Brace ) {
1286- let ( fields, recovered) = self . parse_record_struct_body ( "struct" ) ?;
1287+ let ( fields, recovered) =
1288+ self . parse_record_struct_body ( "struct" , generics. where_clause . has_where_token ) ?;
12871289 VariantData :: Struct ( fields, recovered)
12881290 // Tuple-style struct definition with optional where-clause.
12891291 } else if self . token == token:: OpenDelim ( token:: Paren ) {
@@ -1313,10 +1315,12 @@ impl<'a> Parser<'a> {
13131315
13141316 let vdata = if self . token . is_keyword ( kw:: Where ) {
13151317 generics. where_clause = self . parse_where_clause ( ) ?;
1316- let ( fields, recovered) = self . parse_record_struct_body ( "union" ) ?;
1318+ let ( fields, recovered) =
1319+ self . parse_record_struct_body ( "union" , generics. where_clause . has_where_token ) ?;
13171320 VariantData :: Struct ( fields, recovered)
13181321 } else if self . token == token:: OpenDelim ( token:: Brace ) {
1319- let ( fields, recovered) = self . parse_record_struct_body ( "union" ) ?;
1322+ let ( fields, recovered) =
1323+ self . parse_record_struct_body ( "union" , generics. where_clause . has_where_token ) ?;
13201324 VariantData :: Struct ( fields, recovered)
13211325 } else {
13221326 let token_str = super :: token_descr ( & self . token ) ;
@@ -1332,6 +1336,7 @@ impl<'a> Parser<'a> {
13321336 fn parse_record_struct_body (
13331337 & mut self ,
13341338 adt_ty : & str ,
1339+ parsed_where : bool ,
13351340 ) -> PResult < ' a , ( Vec < FieldDef > , /* recovered */ bool ) > {
13361341 let mut fields = Vec :: new ( ) ;
13371342 let mut recovered = false ;
@@ -1353,9 +1358,19 @@ impl<'a> Parser<'a> {
13531358 self . eat ( & token:: CloseDelim ( token:: Brace ) ) ;
13541359 } else {
13551360 let token_str = super :: token_descr ( & self . token ) ;
1356- let msg = & format ! ( "expected `where`, or `{{` after struct name, found {}" , token_str) ;
1361+ let msg = & format ! (
1362+ "expected {}`{{` after struct name, found {}" ,
1363+ if parsed_where { "" } else { "`where`, or " } ,
1364+ token_str
1365+ ) ;
13571366 let mut err = self . struct_span_err ( self . token . span , msg) ;
1358- err. span_label ( self . token . span , "expected `where`, or `{` after struct name" ) ;
1367+ err. span_label (
1368+ self . token . span ,
1369+ format ! (
1370+ "expected {}`{{` after struct name" ,
1371+ if parsed_where { "" } else { "`where`, or " }
1372+ ) ,
1373+ ) ;
13591374 return Err ( err) ;
13601375 }
13611376
0 commit comments