Remove ParseSess
methods that duplicate DiagCtxt
methods.
Also add missing `#[track_caller]` attributes to `DiagCtxt` methods as necessary to keep tests working.
This commit is contained in:
parent
ec9af0d6cb
commit
d51db05d7e
22 changed files with 256 additions and 308 deletions
|
@ -524,7 +524,7 @@ impl<'a> Parser<'a> {
|
|||
//
|
||||
// let x = 32:
|
||||
// let y = 42;
|
||||
self.sess.emit_err(ExpectedSemi {
|
||||
self.dcx().emit_err(ExpectedSemi {
|
||||
span: self.token.span,
|
||||
token: self.token.clone(),
|
||||
unexpected_token_label: None,
|
||||
|
@ -549,7 +549,7 @@ impl<'a> Parser<'a> {
|
|||
// let x = 32
|
||||
// let y = 42;
|
||||
let span = self.prev_token.span.shrink_to_hi();
|
||||
self.sess.emit_err(ExpectedSemi {
|
||||
self.dcx().emit_err(ExpectedSemi {
|
||||
span,
|
||||
token: self.token.clone(),
|
||||
unexpected_token_label: Some(self.token.span),
|
||||
|
@ -564,13 +564,13 @@ impl<'a> Parser<'a> {
|
|||
&& expected.iter().any(|tok| matches!(tok, TokenType::Token(TokenKind::Eq)))
|
||||
{
|
||||
// Likely typo: `=` → `==` in let expr or enum item
|
||||
return Err(self.sess.create_err(UseEqInstead { span: self.token.span }));
|
||||
return Err(self.dcx().create_err(UseEqInstead { span: self.token.span }));
|
||||
}
|
||||
|
||||
if self.token.is_keyword(kw::Move) && self.prev_token.is_keyword(kw::Async) {
|
||||
// The 2015 edition is in use because parsing of `async move` has failed.
|
||||
let span = self.prev_token.span.to(self.token.span);
|
||||
return Err(self.sess.create_err(AsyncMoveBlockIn2015 { span }));
|
||||
return Err(self.dcx().create_err(AsyncMoveBlockIn2015 { span }));
|
||||
}
|
||||
|
||||
let expect = tokens_to_string(&expected);
|
||||
|
@ -724,7 +724,7 @@ impl<'a> Parser<'a> {
|
|||
pub(super) fn attr_on_non_tail_expr(&self, expr: &Expr) {
|
||||
// Missing semicolon typo error.
|
||||
let span = self.prev_token.span.shrink_to_hi();
|
||||
let mut err = self.sess.create_err(ExpectedSemi {
|
||||
let mut err = self.dcx().create_err(ExpectedSemi {
|
||||
span,
|
||||
token: self.token.clone(),
|
||||
unexpected_token_label: Some(self.token.span),
|
||||
|
@ -901,7 +901,7 @@ impl<'a> Parser<'a> {
|
|||
if let Ok(extend_before) = sm.span_extend_prev_while(before, |t| {
|
||||
t.is_alphanumeric() || t == ':' || t == '_'
|
||||
}) {
|
||||
Err(self.sess.create_err(StructLiteralNeedingParens {
|
||||
Err(self.dcx().create_err(StructLiteralNeedingParens {
|
||||
span: maybe_struct_name.span.to(expr.span),
|
||||
sugg: StructLiteralNeedingParensSugg {
|
||||
before: extend_before.shrink_to_lo(),
|
||||
|
@ -912,7 +912,7 @@ impl<'a> Parser<'a> {
|
|||
return None;
|
||||
}
|
||||
} else {
|
||||
self.sess.emit_err(StructLiteralBodyWithoutPath {
|
||||
self.dcx().emit_err(StructLiteralBodyWithoutPath {
|
||||
span: expr.span,
|
||||
sugg: StructLiteralBodyWithoutPathSugg {
|
||||
before: expr.span.shrink_to_lo(),
|
||||
|
@ -1117,7 +1117,7 @@ impl<'a> Parser<'a> {
|
|||
let span = lo.until(self.token.span);
|
||||
|
||||
let num_extra_brackets = number_of_gt + number_of_shr * 2;
|
||||
self.sess.emit_err(UnmatchedAngleBrackets { span, num_extra_brackets });
|
||||
self.dcx().emit_err(UnmatchedAngleBrackets { span, num_extra_brackets });
|
||||
return true;
|
||||
}
|
||||
false
|
||||
|
@ -1149,7 +1149,7 @@ impl<'a> Parser<'a> {
|
|||
// Recover from bad turbofish: `foo.collect::Vec<_>()`.
|
||||
segment.args = Some(AngleBracketedArgs { args, span }.into());
|
||||
|
||||
self.sess.emit_err(GenericParamsWithoutAngleBrackets {
|
||||
self.dcx().emit_err(GenericParamsWithoutAngleBrackets {
|
||||
span,
|
||||
sugg: GenericParamsWithoutAngleBracketsSugg {
|
||||
left: span.shrink_to_lo(),
|
||||
|
@ -1403,7 +1403,7 @@ impl<'a> Parser<'a> {
|
|||
match self.parse_expr() {
|
||||
Ok(_) => {
|
||||
// 99% certain that the suggestion is correct, continue parsing.
|
||||
self.sess.emit_err(err);
|
||||
self.dcx().emit_err(err);
|
||||
// FIXME: actually check that the two expressions in the binop are
|
||||
// paths and resynthesize new fn call expression instead of using
|
||||
// `ExprKind::Err` placeholder.
|
||||
|
@ -1431,7 +1431,7 @@ impl<'a> Parser<'a> {
|
|||
match self.consume_fn_args() {
|
||||
Err(()) => Err(self.dcx().create_err(err)),
|
||||
Ok(()) => {
|
||||
self.sess.emit_err(err);
|
||||
self.dcx().emit_err(err);
|
||||
// FIXME: actually check that the two expressions in the binop are
|
||||
// paths and resynthesize new fn call expression instead of using
|
||||
// `ExprKind::Err` placeholder.
|
||||
|
@ -1451,7 +1451,7 @@ impl<'a> Parser<'a> {
|
|||
// misformatted turbofish, for instance), suggest a correct form.
|
||||
if self.attempt_chained_comparison_suggestion(&mut err, inner_op, outer_op)
|
||||
{
|
||||
self.sess.emit_err(err);
|
||||
self.dcx().emit_err(err);
|
||||
mk_err_expr(self, inner_op.span.to(self.prev_token.span))
|
||||
} else {
|
||||
// These cases cause too many knock-down errors, bail out (#61329).
|
||||
|
@ -1461,7 +1461,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
let recover =
|
||||
self.attempt_chained_comparison_suggestion(&mut err, inner_op, outer_op);
|
||||
self.sess.emit_err(err);
|
||||
self.dcx().emit_err(err);
|
||||
if recover {
|
||||
return mk_err_expr(self, inner_op.span.to(self.prev_token.span));
|
||||
}
|
||||
|
@ -1494,7 +1494,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
pub(super) fn maybe_report_ambiguous_plus(&mut self, impl_dyn_multi: bool, ty: &Ty) {
|
||||
if impl_dyn_multi {
|
||||
self.sess.emit_err(AmbiguousPlus { sum_ty: pprust::ty_to_string(ty), span: ty.span });
|
||||
self.dcx().emit_err(AmbiguousPlus { sum_ty: pprust::ty_to_string(ty), span: ty.span });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1502,7 +1502,7 @@ impl<'a> Parser<'a> {
|
|||
pub(super) fn maybe_recover_from_question_mark(&mut self, ty: P<Ty>) -> P<Ty> {
|
||||
if self.token == token::Question {
|
||||
self.bump();
|
||||
self.sess.emit_err(QuestionMarkInType {
|
||||
self.dcx().emit_err(QuestionMarkInType {
|
||||
span: self.prev_token.span,
|
||||
sugg: QuestionMarkInTypeSugg {
|
||||
left: ty.span.shrink_to_lo(),
|
||||
|
@ -1539,7 +1539,7 @@ impl<'a> Parser<'a> {
|
|||
match self.parse_expr() {
|
||||
Ok(_) => {
|
||||
return Err(self
|
||||
.sess
|
||||
.dcx()
|
||||
.create_err(TernaryOperator { span: self.token.span.with_lo(lo) }));
|
||||
}
|
||||
Err(err) => {
|
||||
|
@ -1583,7 +1583,7 @@ impl<'a> Parser<'a> {
|
|||
_ => BadTypePlusSub::ExpectPath { span: sum_span },
|
||||
};
|
||||
|
||||
self.sess.emit_err(BadTypePlus { ty: pprust::ty_to_string(ty), span: sum_span, sub });
|
||||
self.dcx().emit_err(BadTypePlus { ty: pprust::ty_to_string(ty), span: sum_span, sub });
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1761,7 +1761,7 @@ impl<'a> Parser<'a> {
|
|||
self.parse_path_segments(&mut path.segments, T::PATH_STYLE, None)?;
|
||||
path.span = ty_span.to(self.prev_token.span);
|
||||
|
||||
self.sess.emit_err(BadQPathStage2 {
|
||||
self.dcx().emit_err(BadQPathStage2 {
|
||||
span: ty_span,
|
||||
wrap: WrapType { lo: ty_span.shrink_to_lo(), hi: ty_span.shrink_to_hi() },
|
||||
});
|
||||
|
@ -1793,7 +1793,7 @@ impl<'a> Parser<'a> {
|
|||
err.name = name;
|
||||
}
|
||||
}
|
||||
self.sess.emit_err(err);
|
||||
self.dcx().emit_err(err);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
@ -1863,7 +1863,7 @@ impl<'a> Parser<'a> {
|
|||
&& self.token == token::Colon
|
||||
&& self.look_ahead(1, |next| line_idx(self.token.span) < line_idx(next.span))
|
||||
{
|
||||
self.sess.emit_err(ColonAsSemi {
|
||||
self.dcx().emit_err(ColonAsSemi {
|
||||
span: self.token.span,
|
||||
type_ascription: self.sess.unstable_features.is_nightly_build().then_some(()),
|
||||
});
|
||||
|
@ -1924,7 +1924,7 @@ impl<'a> Parser<'a> {
|
|||
_ => Applicability::MachineApplicable,
|
||||
};
|
||||
|
||||
self.sess.emit_err(IncorrectAwait {
|
||||
self.dcx().emit_err(IncorrectAwait {
|
||||
span,
|
||||
sugg_span: (span, applicability),
|
||||
expr: self.span_to_snippet(expr.span).unwrap_or_else(|_| pprust::expr_to_string(expr)),
|
||||
|
@ -1945,7 +1945,7 @@ impl<'a> Parser<'a> {
|
|||
let span = lo.to(self.token.span);
|
||||
self.bump(); // )
|
||||
|
||||
self.sess.emit_err(IncorrectUseOfAwait { span });
|
||||
self.dcx().emit_err(IncorrectUseOfAwait { span });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2119,7 +2119,7 @@ impl<'a> Parser<'a> {
|
|||
pub(super) fn check_for_for_in_in_typo(&mut self, in_span: Span) {
|
||||
if self.eat_keyword(kw::In) {
|
||||
// a common typo: `for _ in in bar {}`
|
||||
self.sess.emit_err(InInTypo {
|
||||
self.dcx().emit_err(InInTypo {
|
||||
span: self.prev_token.span,
|
||||
sugg_span: in_span.until(self.prev_token.span),
|
||||
});
|
||||
|
@ -2128,7 +2128,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
pub(super) fn eat_incorrect_doc_comment_for_param_type(&mut self) {
|
||||
if let token::DocComment(..) = self.token.kind {
|
||||
self.sess.emit_err(DocCommentOnParamType { span: self.token.span });
|
||||
self.dcx().emit_err(DocCommentOnParamType { span: self.token.span });
|
||||
self.bump();
|
||||
} else if self.token == token::Pound
|
||||
&& self.look_ahead(1, |t| *t == token::OpenDelim(Delimiter::Bracket))
|
||||
|
@ -2140,7 +2140,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
let sp = lo.to(self.token.span);
|
||||
self.bump();
|
||||
self.sess.emit_err(AttributeOnParamType { span: sp });
|
||||
self.dcx().emit_err(AttributeOnParamType { span: sp });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2261,7 +2261,7 @@ impl<'a> Parser<'a> {
|
|||
self.expect(&token::Colon)?;
|
||||
let ty = self.parse_ty()?;
|
||||
|
||||
self.sess.emit_err(PatternMethodParamWithoutBody { span: pat.span });
|
||||
self.dcx().emit_err(PatternMethodParamWithoutBody { span: pat.span });
|
||||
|
||||
// Pretend the pattern is `_`, to avoid duplicate errors from AST validation.
|
||||
let pat =
|
||||
|
@ -2272,7 +2272,7 @@ impl<'a> Parser<'a> {
|
|||
pub(super) fn recover_bad_self_param(&mut self, mut param: Param) -> PResult<'a, Param> {
|
||||
let span = param.pat.span;
|
||||
param.ty.kind = TyKind::Err;
|
||||
self.sess.emit_err(SelfParamNotFirst { span });
|
||||
self.dcx().emit_err(SelfParamNotFirst { span });
|
||||
Ok(param)
|
||||
}
|
||||
|
||||
|
@ -2474,7 +2474,7 @@ impl<'a> Parser<'a> {
|
|||
err
|
||||
})?;
|
||||
if !self.expr_is_valid_const_arg(&expr) {
|
||||
self.sess.emit_err(ConstGenericWithoutBraces {
|
||||
self.dcx().emit_err(ConstGenericWithoutBraces {
|
||||
span: expr.span,
|
||||
sugg: ConstGenericWithoutBracesSugg {
|
||||
left: expr.span.shrink_to_lo(),
|
||||
|
@ -2516,7 +2516,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
_ => None,
|
||||
};
|
||||
self.sess.emit_err(UnexpectedConstParamDeclaration { span: param.span(), sugg });
|
||||
self.dcx().emit_err(UnexpectedConstParamDeclaration { span: param.span(), sugg });
|
||||
|
||||
let value = self.mk_expr_err(param.span());
|
||||
Some(GenericArg::Const(AnonConst { id: ast::DUMMY_NODE_ID, value }))
|
||||
|
@ -2539,7 +2539,7 @@ impl<'a> Parser<'a> {
|
|||
let mut err = UnexpectedConstInGenericParam { span: start, to_remove: None };
|
||||
if self.check_const_arg() {
|
||||
err.to_remove = Some(start.until(self.token.span));
|
||||
self.sess.emit_err(err);
|
||||
self.dcx().emit_err(err);
|
||||
Ok(Some(GenericArg::Const(self.parse_const_arg()?)))
|
||||
} else {
|
||||
let after_kw_const = self.token.span;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue