@@ -306,8 +306,7 @@ impl<'a> Parser<'a> {
306
306
// possible public struct definition where `struct` was forgotten
307
307
let ident = self . parse_ident ( ) . unwrap ( ) ;
308
308
let msg = format ! ( "add `struct` here to parse `{}` as a public struct" , ident) ;
309
- let mut err =
310
- self . diagnostic ( ) . struct_span_err ( sp, "missing `struct` for struct definition" ) ;
309
+ let mut err = self . struct_span_err ( sp, "missing `struct` for struct definition" ) ;
311
310
err. span_suggestion_short (
312
311
sp,
313
312
& msg,
@@ -335,7 +334,7 @@ impl<'a> Parser<'a> {
335
334
} ;
336
335
337
336
let msg = format ! ( "missing `{}` for {} definition" , kw, kw_name) ;
338
- let mut err = self . diagnostic ( ) . struct_span_err ( sp, & msg) ;
337
+ let mut err = self . struct_span_err ( sp, & msg) ;
339
338
if !ambiguous {
340
339
self . consume_block ( token:: Brace , ConsumeClosingDelim :: Yes ) ;
341
340
let suggestion =
@@ -375,7 +374,7 @@ impl<'a> Parser<'a> {
375
374
( "fn` or `struct" , "function or struct" , true )
376
375
} ;
377
376
let msg = format ! ( "missing `{}` for {} definition" , kw, kw_name) ;
378
- let mut err = self . diagnostic ( ) . struct_span_err ( sp, & msg) ;
377
+ let mut err = self . struct_span_err ( sp, & msg) ;
379
378
if !ambiguous {
380
379
err. span_suggestion_short (
381
380
sp,
@@ -446,9 +445,7 @@ impl<'a> Parser<'a> {
446
445
// FAILURE TO PARSE ITEM
447
446
match visibility. node {
448
447
VisibilityKind :: Inherited => { }
449
- _ => {
450
- return Err ( self . span_fatal ( self . prev_span , "unmatched visibility `pub`" ) ) ;
451
- }
448
+ _ => return Err ( self . struct_span_err ( self . prev_span , "unmatched visibility `pub`" ) ) ,
452
449
}
453
450
454
451
if !attributes_allowed && !attrs. is_empty ( ) {
@@ -466,7 +463,7 @@ impl<'a> Parser<'a> {
466
463
_ => "expected item after attributes" ,
467
464
} ;
468
465
469
- let mut err = self . diagnostic ( ) . struct_span_err ( self . prev_span , message) ;
466
+ let mut err = self . struct_span_err ( self . prev_span , message) ;
470
467
if attrs. last ( ) . unwrap ( ) . is_doc_comment ( ) {
471
468
err. span_label ( self . prev_span , "this doc comment doesn't document anything" ) ;
472
469
}
@@ -536,7 +533,6 @@ impl<'a> Parser<'a> {
536
533
// ^^ `sp` below will point to this
537
534
let sp = prev_span. between ( self . prev_span ) ;
538
535
let mut err = self
539
- . diagnostic ( )
540
536
. struct_span_err ( sp, & format ! ( "{} for {}-item declaration" , expected_kinds, item_type) ) ;
541
537
err. span_label ( sp, expected_kinds) ;
542
538
err
@@ -619,7 +615,7 @@ impl<'a> Parser<'a> {
619
615
// This notably includes paths passed through `ty` macro fragments (#46438).
620
616
TyKind :: Path ( None , path) => path,
621
617
_ => {
622
- self . span_err ( ty_first. span , "expected a trait, found type" ) ;
618
+ self . struct_span_err ( ty_first. span , "expected a trait, found type" ) . emit ( ) ;
623
619
err_path ( ty_first. span )
624
620
}
625
621
} ;
@@ -1349,10 +1345,11 @@ impl<'a> Parser<'a> {
1349
1345
body
1350
1346
} else {
1351
1347
let token_str = super :: token_descr ( & self . token ) ;
1352
- let mut err = self . fatal ( & format ! (
1348
+ let msg = & format ! (
1353
1349
"expected `where`, `{{`, `(`, or `;` after struct name, found {}" ,
1354
1350
token_str
1355
- ) ) ;
1351
+ ) ;
1352
+ let mut err = self . struct_span_err ( self . token . span , msg) ;
1356
1353
err. span_label ( self . token . span , "expected `where`, `{`, `(`, or `;` after struct name" ) ;
1357
1354
return Err ( err) ;
1358
1355
} ;
@@ -1375,8 +1372,8 @@ impl<'a> Parser<'a> {
1375
1372
VariantData :: Struct ( fields, recovered)
1376
1373
} else {
1377
1374
let token_str = super :: token_descr ( & self . token ) ;
1378
- let mut err = self
1379
- . fatal ( & format ! ( "expected `where` or `{{` after union name, found {}" , token_str ) ) ;
1375
+ let msg = & format ! ( "expected `where` or `{{` after union name, found {}" , token_str ) ;
1376
+ let mut err = self . struct_span_err ( self . token . span , msg ) ;
1380
1377
err. span_label ( self . token . span , "expected `where` or `{` after union name" ) ;
1381
1378
return Err ( err) ;
1382
1379
} ;
@@ -1412,10 +1409,8 @@ impl<'a> Parser<'a> {
1412
1409
self . eat ( & token:: CloseDelim ( token:: Brace ) ) ;
1413
1410
} else {
1414
1411
let token_str = super :: token_descr ( & self . token ) ;
1415
- let mut err = self . fatal ( & format ! (
1416
- "expected `where`, or `{{` after struct name, found {}" ,
1417
- token_str
1418
- ) ) ;
1412
+ let msg = & format ! ( "expected `where`, or `{{` after struct name, found {}" , token_str) ;
1413
+ let mut err = self . struct_span_err ( self . token . span , msg) ;
1419
1414
err. span_label ( self . token . span , "expected `where`, or `{` after struct name" ) ;
1420
1415
return Err ( err) ;
1421
1416
}
@@ -1603,9 +1598,8 @@ impl<'a> Parser<'a> {
1603
1598
VisibilityKind :: Inherited => { }
1604
1599
_ => {
1605
1600
let mut err = if self . token . is_keyword ( sym:: macro_rules) {
1606
- let mut err = self
1607
- . diagnostic ( )
1608
- . struct_span_err ( sp, "can't qualify macro_rules invocation with `pub`" ) ;
1601
+ let mut err =
1602
+ self . struct_span_err ( sp, "can't qualify macro_rules invocation with `pub`" ) ;
1609
1603
err. span_suggestion (
1610
1604
sp,
1611
1605
"try exporting the macro" ,
@@ -1614,9 +1608,8 @@ impl<'a> Parser<'a> {
1614
1608
) ;
1615
1609
err
1616
1610
} else {
1617
- let mut err = self
1618
- . diagnostic ( )
1619
- . struct_span_err ( sp, "can't qualify macro invocation with `pub`" ) ;
1611
+ let mut err =
1612
+ self . struct_span_err ( sp, "can't qualify macro invocation with `pub`" ) ;
1620
1613
err. help ( "try adjusting the macro to put `pub` inside the invocation" ) ;
1621
1614
err
1622
1615
} ;
0 commit comments