use super::pat::Expected;
-use super::ty::{AllowPlus, IsAsCast};
+use super::ty::{AllowPlus, RecoverQuestionMark};
use super::{
BlockMode, CommaRecoveryMode, Parser, PathStyle, RecoverColon, RecoverComma, Restrictions,
SemiColonMode, SeqSep, TokenExpectType, TokenType,
};
use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::FxHashSet;
-use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorReported};
+use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed};
use rustc_errors::{Applicability, DiagnosticBuilder, Handler, PResult};
use rustc_span::source_map::Spanned;
use rustc_span::symbol::{kw, Ident};
self,
sp: impl Into<MultiSpan>,
handler: &Handler,
- ) -> DiagnosticBuilder<'_, ErrorReported> {
+ ) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
match self {
Error::UselessDocComment => {
let mut err = struct_span_err!(
&self,
sp: S,
err: Error,
- ) -> DiagnosticBuilder<'a, ErrorReported> {
+ ) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
err.span_err(sp, self.diagnostic())
}
&self,
sp: S,
m: &str,
- ) -> DiagnosticBuilder<'a, ErrorReported> {
+ ) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
self.sess.span_diagnostic.struct_span_err(sp, m)
}
self.sess.source_map().span_to_snippet(span)
}
- pub(super) fn expected_ident_found(&self) -> DiagnosticBuilder<'a, ErrorReported> {
+ pub(super) fn expected_ident_found(&self) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
let mut err = self.struct_span_err(
self.token.span,
&format!("expected identifier, found {}", super::token_descr(&self.token)),
/// encounter a parse error when encountering the first `,`.
pub(super) fn check_mistyped_turbofish_with_multiple_type_params(
&mut self,
- mut e: DiagnosticBuilder<'a, ErrorReported>,
+ mut e: DiagnosticBuilder<'a, ErrorGuaranteed>,
expr: &mut P<Expr>,
) -> PResult<'a, ()> {
- if let ExprKind::Binary(binop, _, _) = &expr.kind {
- if let ast::BinOpKind::Lt = binop.node {
- if self.eat(&token::Comma) {
- let x = self.parse_seq_to_before_end(
- &token::Gt,
- SeqSep::trailing_allowed(token::Comma),
- |p| p.parse_generic_arg(None),
- );
- match x {
- Ok((_, _, false)) => {
- if self.eat(&token::Gt) {
- e.span_suggestion_verbose(
- binop.span.shrink_to_lo(),
- TURBOFISH_SUGGESTION_STR,
- "::".to_string(),
- Applicability::MaybeIncorrect,
- )
- .emit();
- match self.parse_expr() {
- Ok(_) => {
- *expr =
- self.mk_expr_err(expr.span.to(self.prev_token.span));
- return Ok(());
- }
- Err(err) => {
- *expr = self.mk_expr_err(expr.span);
- err.cancel();
- }
- }
+ if let ExprKind::Binary(binop, _, _) = &expr.kind
+ && let ast::BinOpKind::Lt = binop.node
+ && self.eat(&token::Comma)
+ {
+ let x = self.parse_seq_to_before_end(
+ &token::Gt,
+ SeqSep::trailing_allowed(token::Comma),
+ |p| p.parse_generic_arg(None),
+ );
+ match x {
+ Ok((_, _, false)) => {
+ if self.eat(&token::Gt) {
+ e.span_suggestion_verbose(
+ binop.span.shrink_to_lo(),
+ TURBOFISH_SUGGESTION_STR,
+ "::".to_string(),
+ Applicability::MaybeIncorrect,
+ )
+ .emit();
+ match self.parse_expr() {
+ Ok(_) => {
+ *expr =
+ self.mk_expr_err(expr.span.to(self.prev_token.span));
+ return Ok(());
+ }
+ Err(err) => {
+ *expr = self.mk_expr_err(expr.span);
+ err.cancel();
}
}
- Err(err) => {
- err.cancel();
- }
- _ => {}
}
}
+ Err(err) => {
+ err.cancel();
+ }
+ _ => {}
}
}
Err(e)
outer_op: &Spanned<AssocOp>,
) -> bool /* advanced the cursor */ {
if let ExprKind::Binary(op, ref l1, ref r1) = inner_op.kind {
- if let ExprKind::Field(_, ident) = l1.kind {
- if ident.as_str().parse::<i32>().is_err() && !matches!(r1.kind, ExprKind::Lit(_)) {
- // The parser has encountered `foo.bar<baz`, the likelihood of the turbofish
- // suggestion being the only one to apply is high.
- return false;
- }
+ if let ExprKind::Field(_, ident) = l1.kind
+ && ident.as_str().parse::<i32>().is_err()
+ && !matches!(r1.kind, ExprKind::Lit(_))
+ {
+ // The parser has encountered `foo.bar<baz`, the likelihood of the turbofish
+ // suggestion being the only one to apply is high.
+ return false;
}
let mut enclose = |left: Span, right: Span| {
err.multipart_suggestion(
pub(super) fn maybe_recover_from_question_mark(
&mut self,
ty: P<Ty>,
- is_as_cast: IsAsCast,
+ recover_question_mark: RecoverQuestionMark,
) -> P<Ty> {
- if let IsAsCast::Yes = is_as_cast {
+ if let RecoverQuestionMark::No = recover_question_mark {
return ty;
}
if self.token == token::Question {
pub(super) fn recover_closing_delimiter(
&mut self,
tokens: &[TokenKind],
- mut err: DiagnosticBuilder<'a, ErrorReported>,
+ mut err: DiagnosticBuilder<'a, ErrorGuaranteed>,
) -> PResult<'a, bool> {
let mut pos = None;
// We want to use the last closing delim that would apply.
}
}
- pub(super) fn expected_expression_found(&self) -> DiagnosticBuilder<'a, ErrorReported> {
+ pub(super) fn expected_expression_found(&self) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
let (span, msg) = match (&self.token.kind, self.subparser_name) {
(&token::Eof, Some(origin)) => {
let sp = self.sess.source_map().next_point(self.prev_token.span);
pub fn recover_const_arg(
&mut self,
start: Span,
- mut err: DiagnosticBuilder<'a, ErrorReported>,
+ mut err: DiagnosticBuilder<'a, ErrorGuaranteed>,
) -> PResult<'a, GenericArg> {
let is_op_or_dot = AssocOp::from_token(&self.token)
.and_then(|op| {
/// Creates a dummy const argument, and reports that the expression must be enclosed in braces
pub fn dummy_const_arg_needs_braces(
&self,
- mut err: DiagnosticBuilder<'a, ErrorReported>,
+ mut err: DiagnosticBuilder<'a, ErrorGuaranteed>,
span: Span,
) -> GenericArg {
err.multipart_suggestion(
pub(super) fn incorrect_move_async_order_found(
&self,
move_async_span: Span,
- ) -> DiagnosticBuilder<'a, ErrorReported> {
+ ) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
let mut err =
self.struct_span_err(move_async_span, "the order of `move` and `async` is incorrect");
err.span_suggestion_verbose(