@@ -233,8 +233,8 @@ pub struct Parser<'a> {
233233 /// error.
234234 crate unclosed_delims : Vec < UnmatchedBrace > ,
235235 last_unexpected_token_span : Option < Span > ,
236- /// If `true` , this `Parser` is not parsing Rust code but rather a macro call.
237- is_subparser : Option < & ' static str > ,
236+ /// If present , this `Parser` is not parsing Rust code but rather a macro call.
237+ crate subparser_name : Option < & ' static str > ,
238238}
239239
240240impl < ' a > Drop for Parser < ' a > {
@@ -541,7 +541,7 @@ impl<'a> Parser<'a> {
541541 directory : Option < Directory < ' a > > ,
542542 recurse_into_file_modules : bool ,
543543 desugar_doc_comments : bool ,
544- is_subparser : Option < & ' static str > ,
544+ subparser_name : Option < & ' static str > ,
545545 ) -> Self {
546546 let mut parser = Parser {
547547 sess,
@@ -572,7 +572,7 @@ impl<'a> Parser<'a> {
572572 max_angle_bracket_count : 0 ,
573573 unclosed_delims : Vec :: new ( ) ,
574574 last_unexpected_token_span : None ,
575- is_subparser ,
575+ subparser_name ,
576576 } ;
577577
578578 let tok = parser. next_tok ( ) ;
@@ -636,56 +636,13 @@ impl<'a> Parser<'a> {
636636 }
637637
638638 /// Expects and consumes the token `t`. Signals an error if the next token is not `t`.
639- pub fn expect ( & mut self , t : & token:: Token ) -> PResult < ' a , bool /* recovered */ > {
639+ pub fn expect ( & mut self , t : & token:: Token ) -> PResult < ' a , bool /* recovered */ > {
640640 if self . expected_tokens . is_empty ( ) {
641641 if self . token == * t {
642642 self . bump ( ) ;
643643 Ok ( false )
644644 } else {
645- let token_str = pprust:: token_to_string ( t) ;
646- let this_token_str = self . this_token_descr ( ) ;
647- let ( prev_sp, sp) = match ( & self . token , self . is_subparser ) {
648- // Point at the end of the macro call when reaching end of macro arguments.
649- ( token:: Token :: Eof , Some ( _) ) => {
650- let sp = self . sess . source_map ( ) . next_point ( self . span ) ;
651- ( sp, sp)
652- }
653- // We don't want to point at the following span after DUMMY_SP.
654- // This happens when the parser finds an empty TokenStream.
655- _ if self . prev_span == DUMMY_SP => ( self . span , self . span ) ,
656- // EOF, don't want to point at the following char, but rather the last token.
657- ( token:: Token :: Eof , None ) => ( self . prev_span , self . span ) ,
658- _ => ( self . sess . source_map ( ) . next_point ( self . prev_span ) , self . span ) ,
659- } ;
660- let msg = format ! (
661- "expected `{}`, found {}" ,
662- token_str,
663- match ( & self . token, self . is_subparser) {
664- ( token:: Token :: Eof , Some ( origin) ) => format!( "end of {}" , origin) ,
665- _ => this_token_str,
666- } ,
667- ) ;
668- let mut err = self . struct_span_err ( sp, & msg) ;
669- let label_exp = format ! ( "expected `{}`" , token_str) ;
670- match self . recover_closing_delimiter ( & [ t. clone ( ) ] , err) {
671- Err ( e) => err = e,
672- Ok ( recovered) => {
673- return Ok ( recovered) ;
674- }
675- }
676- let cm = self . sess . source_map ( ) ;
677- match ( cm. lookup_line ( prev_sp. lo ( ) ) , cm. lookup_line ( sp. lo ( ) ) ) {
678- ( Ok ( ref a) , Ok ( ref b) ) if a. line == b. line => {
679- // When the spans are in the same line, it means that the only content
680- // between them is whitespace, point only at the found token.
681- err. span_label ( sp, label_exp) ;
682- }
683- _ => {
684- err. span_label ( prev_sp, label_exp) ;
685- err. span_label ( sp, "unexpected token" ) ;
686- }
687- }
688- Err ( err)
645+ self . unexpected_try_recover ( t)
689646 }
690647 } else {
691648 self . expect_one_of ( slice:: from_ref ( t) , & [ ] )
@@ -2644,7 +2601,7 @@ impl<'a> Parser<'a> {
26442601 }
26452602 Err ( mut err) => {
26462603 self . cancel ( & mut err) ;
2647- let ( span, msg) = match ( & self . token , self . is_subparser ) {
2604+ let ( span, msg) = match ( & self . token , self . subparser_name ) {
26482605 ( & token:: Token :: Eof , Some ( origin) ) => {
26492606 let sp = self . sess . source_map ( ) . next_point ( self . span ) ;
26502607 ( sp, format ! ( "expected expression, found end of {}" , origin) )
0 commit comments