@@ -306,8 +306,7 @@ impl<'a> Parser<'a> {
306306 // possible public struct definition where `struct` was forgotten
307307 let ident = self . parse_ident ( ) . unwrap ( ) ;
308308 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" ) ;
311310 err. span_suggestion_short (
312311 sp,
313312 & msg,
@@ -335,7 +334,7 @@ impl<'a> Parser<'a> {
335334 } ;
336335
337336 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) ;
339338 if !ambiguous {
340339 self . consume_block ( token:: Brace , ConsumeClosingDelim :: Yes ) ;
341340 let suggestion =
@@ -375,7 +374,7 @@ impl<'a> Parser<'a> {
375374 ( "fn` or `struct" , "function or struct" , true )
376375 } ;
377376 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) ;
379378 if !ambiguous {
380379 err. span_suggestion_short (
381380 sp,
@@ -446,9 +445,7 @@ impl<'a> Parser<'a> {
446445 // FAILURE TO PARSE ITEM
447446 match visibility. node {
448447 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`" ) ) ,
452449 }
453450
454451 if !attributes_allowed && !attrs. is_empty ( ) {
@@ -466,7 +463,7 @@ impl<'a> Parser<'a> {
466463 _ => "expected item after attributes" ,
467464 } ;
468465
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) ;
470467 if attrs. last ( ) . unwrap ( ) . is_doc_comment ( ) {
471468 err. span_label ( self . prev_span , "this doc comment doesn't document anything" ) ;
472469 }
@@ -536,7 +533,6 @@ impl<'a> Parser<'a> {
536533 // ^^ `sp` below will point to this
537534 let sp = prev_span. between ( self . prev_span ) ;
538535 let mut err = self
539- . diagnostic ( )
540536 . struct_span_err ( sp, & format ! ( "{} for {}-item declaration" , expected_kinds, item_type) ) ;
541537 err. span_label ( sp, expected_kinds) ;
542538 err
@@ -619,7 +615,7 @@ impl<'a> Parser<'a> {
619615 // This notably includes paths passed through `ty` macro fragments (#46438).
620616 TyKind :: Path ( None , path) => path,
621617 _ => {
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 ( ) ;
623619 err_path ( ty_first. span )
624620 }
625621 } ;
@@ -1349,10 +1345,11 @@ impl<'a> Parser<'a> {
13491345 body
13501346 } else {
13511347 let token_str = super :: token_descr ( & self . token ) ;
1352- let mut err = self . fatal ( & format ! (
1348+ let msg = & format ! (
13531349 "expected `where`, `{{`, `(`, or `;` after struct name, found {}" ,
13541350 token_str
1355- ) ) ;
1351+ ) ;
1352+ let mut err = self . struct_span_err ( self . token . span , msg) ;
13561353 err. span_label ( self . token . span , "expected `where`, `{`, `(`, or `;` after struct name" ) ;
13571354 return Err ( err) ;
13581355 } ;
@@ -1375,8 +1372,8 @@ impl<'a> Parser<'a> {
13751372 VariantData :: Struct ( fields, recovered)
13761373 } else {
13771374 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 ) ;
13801377 err. span_label ( self . token . span , "expected `where` or `{` after union name" ) ;
13811378 return Err ( err) ;
13821379 } ;
@@ -1412,10 +1409,8 @@ impl<'a> Parser<'a> {
14121409 self . eat ( & token:: CloseDelim ( token:: Brace ) ) ;
14131410 } else {
14141411 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) ;
14191414 err. span_label ( self . token . span , "expected `where`, or `{` after struct name" ) ;
14201415 return Err ( err) ;
14211416 }
@@ -1603,9 +1598,8 @@ impl<'a> Parser<'a> {
16031598 VisibilityKind :: Inherited => { }
16041599 _ => {
16051600 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`" ) ;
16091603 err. span_suggestion (
16101604 sp,
16111605 "try exporting the macro" ,
@@ -1614,9 +1608,8 @@ impl<'a> Parser<'a> {
16141608 ) ;
16151609 err
16161610 } 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`" ) ;
16201613 err. help ( "try adjusting the macro to put `pub` inside the invocation" ) ;
16211614 err
16221615 } ;
0 commit comments