pub(super) fn unexpected_try_recover(
        &mut self,
        t: &TokenKind,
    ) -> PResult<'a, bool /* recovered */> {
        let token_str = pprust::token_kind_to_string(t);
        let this_token_str = super::token_descr(&self.token);
        let (prev_sp, sp) = match (&self.token.kind, self.subparser_name) {
            // Point at the end of the macro call when reaching end of macro arguments.
            (token::Eof, Some(_)) => {
                let sp = self.sess.source_map().next_point(self.token.span);
                (sp, sp)
            }
            // We don't want to point at the following span after DUMMY_SP.
            // This happens when the parser finds an empty TokenStream.
            _ if self.prev_token.span == DUMMY_SP => (self.token.span, self.token.span),
            // EOF, don't want to point at the following char, but rather the last token.
            (token::Eof, None) => (self.prev_token.span, self.token.span),
            _ => (self.prev_token.span.shrink_to_hi(), self.token.span),
        };
        let msg = format!(
            "expected `{}`, found {}",
            token_str,
            match (&self.token.kind, self.subparser_name) {
                (token::Eof, Some(origin)) => format!("end of {}", origin),
                _ => this_token_str,
            },
        );
        let mut err = self.struct_span_err(sp, &msg);
        let label_exp = format!("expected `{}`", token_str);
        match self.recover_closing_delimiter(&[t.clone()], err) {
            Err(e) => err = e,
            Ok(recovered) => {
                return Ok(recovered);
            }
        }
        let sm = self.sess.source_map();
        if !sm.is_multiline(prev_sp.until(sp)) {
            // When the spans are in the same line, it means that the only content
            // between them is whitespace, point only at the found token.
            err.span_label(sp, label_exp);
        } else {
            err.span_label(prev_sp, label_exp);
            err.span_label(sp, "unexpected token");
        }
        Err(err)
    }
/// Creates a `DiagnosticBuilder` for an unexpected token `t` and tries to recover if it is a
/// closing delimiter.
Creates a `DiagnosticBuilder` for an unexpected token `t` and tries to recover if it is a
closing delimiter.
Creates a ` DiagnosticBuilder ` for an unexpected token ` t ` and tries to recover if it is a closing delimiter .
pub(super) fn unexpected_try_recover(
        &mut self,
        t: &TokenKind,
    ) -> PResult<'a, bool /* recovered */> {
        let token_str = pprust::token_kind_to_string(t);
        let this_token_str = super::token_descr(&self.token);
        let (prev_sp, sp) = match (&self.token.kind, self.subparser_name) {
            // Point at the end of the macro call when reaching end of macro arguments.
            (token::Eof, Some(_)) => {
                let sp = self.sess.source_map().next_point(self.token.span);
                (sp, sp)
            }
            // We don't want to point at the following span after DUMMY_SP.
            // This happens when the parser finds an empty TokenStream.
            _ if self.prev_token.span == DUMMY_SP => (self.token.span, self.token.span),
            // EOF, don't want to point at the following char, but rather the last token.
            (token::Eof, None) => (self.prev_token.span, self.token.span),
            _ => (self.prev_token.span.shrink_to_hi(), self.token.span),
        };
        let msg = format!(
            "expected `{}`, found {}",
            token_str,
            match (&self.token.kind, self.subparser_name) {
                (token::Eof, Some(origin)) => format!("end of {}", origin),
                _ => this_token_str,
            },
        );
        let mut err = self.struct_span_err(sp, &msg);
        let label_exp = format!("expected `{}`", token_str);
        match self.recover_closing_delimiter(&[t.clone()], err) {
            Err(e) => err = e,
            Ok(recovered) => {
                return Ok(recovered);
            }
        }
        let sm = self.sess.source_map();
        if !sm.is_multiline(prev_sp.until(sp)) {
            // When the spans are in the same line, it means that the only content
            // between them is whitespace, point only at the found token.
            err.span_label(sp, label_exp);
        } else {
            err.span_label(prev_sp, label_exp);
            err.span_label(sp, "unexpected token");
        }
        Err(err)
    }
pub ( super ) fn unexpected_try_recover ( & mut self , t : & TokenKind , ) -> PResult < ' a , bool /* recovered */ > { let token_str = pprust :: token_kind_to_string ( t ) ; let this_token_str = super :: token_descr ( & self . token ) ; let ( prev_sp , sp ) = match ( & self . token . kind , self . subparser_name ) { // Point at the end of the macro call when reaching end of macro arguments. ( token :: Eof , Some ( _ ) ) => { let sp = self . sess . source_map ( ) . next_point ( self . token . span ) ; ( sp , sp ) } // We don't want to point at the following span after DUMMY_SP. // This happens when the parser finds an empty TokenStream. _ if self . prev_token . span == DUMMY_SP => ( self . token . span , self . token . span ) , // EOF, don't want to point at the following char, but rather the last token. ( token :: Eof , None ) => ( self . prev_token . span , self . token . span ) , _ => ( self . prev_token . span . shrink_to_hi ( ) , self . token . span ) , } ; let msg = format ! ( " " token_str match ( self token kind self subparser_name ) { ( token Eof Some ( origin ) ) format ( " " origin ) this_token_str } ) ; let mut err = self . struct_span_err ( sp , & msg ) ; let label_exp = format ! ( " " token_str ) ; match self . recover_closing_delimiter ( & [ t . clone ( ) ] , err ) { Err ( e ) => err = e , Ok ( recovered ) => { return Ok ( recovered ) ; } } let sm = self . sess . source_map ( ) ; if ! sm . is_multiline ( prev_sp . until ( sp ) ) { // When the spans are in the same line, it means that the only content // between them is whitespace, point only at the found token. err . span_label ( sp , label_exp ) ; } else { err . span_label ( prev_sp , label_exp ) ; err . span_label ( sp , " " ) ; } Err ( err ) }
Creates a `DiagnosticBuilder` for an unexpected token `t` and tries to recover if it is a
closing delimiter.
Creates a ` DiagnosticBuilder ` for an unexpected token ` t ` and tries to recover if it is a closing delimiter .
&mut self
t
&TokenKind
&mut self
t
&TokenKind