@@ -1221,7 +1221,7 @@ impl<'a> Parser<'a> {
1221
1221
1222
1222
let struct_def = if this. check ( & token:: OpenDelim ( token:: Brace ) ) {
1223
1223
// 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 ) ?;
1225
1225
VariantData :: Struct ( fields, recovered)
1226
1226
} else if this. check ( & token:: OpenDelim ( token:: Paren ) ) {
1227
1227
VariantData :: Tuple ( this. parse_tuple_struct_body ( ) ?, DUMMY_NODE_ID )
@@ -1275,15 +1275,17 @@ impl<'a> Parser<'a> {
1275
1275
VariantData :: Unit ( DUMMY_NODE_ID )
1276
1276
} else {
1277
1277
// 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 ) ?;
1279
1280
VariantData :: Struct ( fields, recovered)
1280
1281
}
1281
1282
// No `where` so: `struct Foo<T>;`
1282
1283
} else if self . eat ( & token:: Semi ) {
1283
1284
VariantData :: Unit ( DUMMY_NODE_ID )
1284
1285
// Record-style struct definition
1285
1286
} 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 ) ?;
1287
1289
VariantData :: Struct ( fields, recovered)
1288
1290
// Tuple-style struct definition with optional where-clause.
1289
1291
} else if self . token == token:: OpenDelim ( token:: Paren ) {
@@ -1313,10 +1315,12 @@ impl<'a> Parser<'a> {
1313
1315
1314
1316
let vdata = if self . token . is_keyword ( kw:: Where ) {
1315
1317
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 ) ?;
1317
1320
VariantData :: Struct ( fields, recovered)
1318
1321
} 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 ) ?;
1320
1324
VariantData :: Struct ( fields, recovered)
1321
1325
} else {
1322
1326
let token_str = super :: token_descr ( & self . token ) ;
@@ -1332,6 +1336,7 @@ impl<'a> Parser<'a> {
1332
1336
fn parse_record_struct_body (
1333
1337
& mut self ,
1334
1338
adt_ty : & str ,
1339
+ parsed_where : bool ,
1335
1340
) -> PResult < ' a , ( Vec < FieldDef > , /* recovered */ bool ) > {
1336
1341
let mut fields = Vec :: new ( ) ;
1337
1342
let mut recovered = false ;
@@ -1353,9 +1358,19 @@ impl<'a> Parser<'a> {
1353
1358
self . eat ( & token:: CloseDelim ( token:: Brace ) ) ;
1354
1359
} else {
1355
1360
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
+ ) ;
1357
1366
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
+ ) ;
1359
1374
return Err ( err) ;
1360
1375
}
1361
1376
0 commit comments