Rename Parser::span_diagnostic as Parser::dcx.

This commit is contained in:
Nicholas Nethercote 2023-12-18 07:37:58 +11:00
parent 09af8a667c
commit 73bac456d4
8 changed files with 40 additions and 42 deletions

View File

@ -55,7 +55,7 @@ impl<'a> Parser<'a> {
} else if let token::DocComment(comment_kind, attr_style, data) = self.token.kind {
if attr_style != ast::AttrStyle::Outer {
let span = self.token.span;
let mut err = self.diagnostic().struct_span_err_with_code(
let mut err = self.dcx().struct_span_err_with_code(
span,
fluent::parse_inner_doc_comment_not_permitted,
error_code!(E0753),
@ -417,7 +417,7 @@ impl<'a> Parser<'a> {
}
Err(InvalidMetaItem { span: self.token.span, token: self.token.clone() }
.into_diagnostic(self.diagnostic()))
.into_diagnostic(self.dcx()))
}
}

View File

@ -266,8 +266,7 @@ impl<'a> Parser<'a> {
if let Some(attr_range) = self.capture_state.inner_attr_ranges.remove(&inner_attr.id) {
inner_attr_replace_ranges.push(attr_range);
} else {
self.diagnostic()
.span_delayed_bug(inner_attr.span, "Missing token range for attribute");
self.dcx().span_delayed_bug(inner_attr.span, "Missing token range for attribute");
}
}

View File

@ -246,14 +246,14 @@ impl<'a> Parser<'a> {
sp: S,
m: impl Into<DiagnosticMessage>,
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
self.diagnostic().struct_span_err(sp, m)
self.dcx().struct_span_err(sp, m)
}
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) -> ! {
self.diagnostic().span_bug(sp, msg)
self.dcx().span_bug(sp, msg)
}
pub(super) fn diagnostic(&self) -> &'a DiagCtxt {
pub(super) fn dcx(&self) -> &'a DiagCtxt {
&self.sess.dcx
}
@ -284,7 +284,7 @@ impl<'a> Parser<'a> {
span: self.prev_token.span,
missing_comma: None,
}
.into_diagnostic(self.diagnostic()));
.into_diagnostic(self.dcx()));
}
let valid_follow = &[
@ -347,7 +347,7 @@ impl<'a> Parser<'a> {
suggest_remove_comma,
help_cannot_start_number,
};
let mut err = err.into_diagnostic(self.diagnostic());
let mut err = err.into_diagnostic(self.dcx());
// if the token we have is a `<`
// it *might* be a misplaced generic
@ -1410,7 +1410,7 @@ impl<'a> Parser<'a> {
// Not entirely sure now, but we bubble the error up with the
// suggestion.
self.restore_snapshot(snapshot);
Err(err.into_diagnostic(self.diagnostic()))
Err(err.into_diagnostic(self.dcx()))
}
}
} else if token::OpenDelim(Delimiter::Parenthesis) == self.token.kind {
@ -1425,7 +1425,7 @@ impl<'a> Parser<'a> {
}
// Consume the fn call arguments.
match self.consume_fn_args() {
Err(()) => Err(err.into_diagnostic(self.diagnostic())),
Err(()) => Err(err.into_diagnostic(self.dcx())),
Ok(()) => {
self.sess.emit_err(err);
// FIXME: actually check that the two expressions in the binop are
@ -1451,7 +1451,7 @@ impl<'a> Parser<'a> {
mk_err_expr(self, inner_op.span.to(self.prev_token.span))
} else {
// These cases cause too many knock-down errors, bail out (#61329).
Err(err.into_diagnostic(self.diagnostic()))
Err(err.into_diagnostic(self.dcx()))
}
};
}
@ -2539,7 +2539,7 @@ impl<'a> Parser<'a> {
Ok(Some(GenericArg::Const(self.parse_const_arg()?)))
} else {
let after_kw_const = self.token.span;
self.recover_const_arg(after_kw_const, err.into_diagnostic(self.diagnostic())).map(Some)
self.recover_const_arg(after_kw_const, err.into_diagnostic(self.dcx())).map(Some)
}
}
@ -2897,7 +2897,7 @@ impl<'a> Parser<'a> {
span: path.span.shrink_to_hi(),
between: between_span,
}
.into_diagnostic(self.diagnostic()));
.into_diagnostic(self.dcx()));
}
}
}

View File

@ -1269,7 +1269,7 @@ impl<'a> Parser<'a> {
.collect(),
},
}
.into_diagnostic(self.diagnostic());
.into_diagnostic(self.dcx());
replacement_err.emit();
let old_err = mem::replace(err, replacement_err);
@ -1693,8 +1693,7 @@ impl<'a> Parser<'a> {
mk_lit_char: impl FnOnce(Symbol, Span) -> L,
err: impl FnOnce(&Self) -> DiagnosticBuilder<'a, ErrorGuaranteed>,
) -> L {
if let Some(mut diag) =
self.diagnostic().steal_diagnostic(lifetime.span, StashKey::LifetimeIsChar)
if let Some(mut diag) = self.dcx().steal_diagnostic(lifetime.span, StashKey::LifetimeIsChar)
{
diag.span_suggestion_verbose(
lifetime.span.shrink_to_hi(),
@ -1884,8 +1883,8 @@ impl<'a> Parser<'a> {
self.bump(); // `#`
let Some((ident, false)) = self.token.ident() else {
let err = errors::ExpectedBuiltinIdent { span: self.token.span }
.into_diagnostic(self.diagnostic());
let err =
errors::ExpectedBuiltinIdent { span: self.token.span }.into_diagnostic(self.dcx());
return Err(err);
};
self.sess.gated_spans.gate(sym::builtin_syntax, ident.span);
@ -1896,7 +1895,7 @@ impl<'a> Parser<'a> {
Ok(res)
} else {
let err = errors::UnknownBuiltinConstruct { span: lo.to(ident.span), name: ident.name }
.into_diagnostic(self.diagnostic());
.into_diagnostic(self.dcx());
return Err(err);
};
self.expect(&TokenKind::CloseDelim(Delimiter::Parenthesis))?;
@ -1960,7 +1959,7 @@ impl<'a> Parser<'a> {
&& matches!(e.kind, ExprKind::Err)
{
let mut err = errors::InvalidInterpolatedExpression { span: self.token.span }
.into_diagnostic(self.diagnostic());
.into_diagnostic(self.dcx());
err.downgrade_to_delayed_bug();
return Err(err);
}
@ -2172,7 +2171,7 @@ impl<'a> Parser<'a> {
return Err(errors::MissingSemicolonBeforeArray {
open_delim: open_delim_span,
semicolon: prev_span.shrink_to_hi(),
}.into_diagnostic(self.diagnostic()));
}.into_diagnostic(self.dcx()));
}
Ok(_) => (),
Err(err) => err.cancel(),
@ -2320,7 +2319,7 @@ impl<'a> Parser<'a> {
if self.check_keyword(kw::Async) {
let move_async_span = self.token.span.with_lo(self.prev_token.span.data().lo);
Err(errors::AsyncMoveOrderIncorrect { span: move_async_span }
.into_diagnostic(self.diagnostic()))
.into_diagnostic(self.dcx()))
} else {
Ok(CaptureBy::Value { move_kw: move_kw_span })
}
@ -2510,7 +2509,7 @@ impl<'a> Parser<'a> {
};
if self.prev_token.kind == token::BinOp(token::Or) {
// This was part of a closure, the that part of the parser recover.
return Err(err.into_diagnostic(self.diagnostic()));
return Err(err.into_diagnostic(self.dcx()));
} else {
Some(self.sess.emit_err(err))
}
@ -3194,8 +3193,7 @@ impl<'a> Parser<'a> {
fn parse_try_block(&mut self, span_lo: Span) -> PResult<'a, P<Expr>> {
let (attrs, body) = self.parse_inner_attrs_and_block()?;
if self.eat_keyword(kw::Catch) {
Err(errors::CatchAfterTry { span: self.prev_token.span }
.into_diagnostic(self.diagnostic()))
Err(errors::CatchAfterTry { span: self.prev_token.span }.into_diagnostic(self.dcx()))
} else {
let span = span_lo.to(body.span);
self.sess.gated_spans.gate(sym::try_blocks, span);

View File

@ -438,7 +438,7 @@ impl<'a> Parser<'a> {
None
};
if let Some(err) = err { Err(err.into_diagnostic(self.diagnostic())) } else { Ok(()) }
if let Some(err) = err { Err(err.into_diagnostic(self.dcx())) } else { Ok(()) }
}
fn parse_item_builtin(&mut self) -> PResult<'a, Option<ItemInfo>> {
@ -759,7 +759,7 @@ impl<'a> Parser<'a> {
if self.look_ahead(1, |tok| tok == &token::CloseDelim(Delimiter::Brace)) {
// FIXME: merge with `DocCommentDoesNotDocumentAnything` (E0585)
struct_span_err!(
self.diagnostic(),
self.dcx(),
self.token.span,
E0584,
"found a documentation comment that doesn't document anything",
@ -1374,7 +1374,7 @@ impl<'a> Parser<'a> {
let span = self.prev_token.span.shrink_to_hi();
let err: DiagnosticBuilder<'_, ErrorGuaranteed> =
errors::MissingConstType { span, colon, kind }.into_diagnostic(self.diagnostic());
errors::MissingConstType { span, colon, kind }.into_diagnostic(self.dcx());
err.stash(span, StashKey::ItemNoType);
// The user intended that the type be inferred,
@ -1391,7 +1391,7 @@ impl<'a> Parser<'a> {
self.bump();
self.sess.emit_err(err);
} else {
return Err(err.into_diagnostic(self.diagnostic()));
return Err(err.into_diagnostic(self.dcx()));
}
}
@ -1591,7 +1591,7 @@ impl<'a> Parser<'a> {
} else {
let err =
errors::UnexpectedTokenAfterStructName::new(self.token.span, self.token.clone());
return Err(err.into_diagnostic(self.diagnostic()));
return Err(err.into_diagnostic(self.dcx()));
};
Ok((class_name, ItemKind::Struct(vdata, generics)))
@ -1787,7 +1787,7 @@ impl<'a> Parser<'a> {
let sp = previous_span.shrink_to_hi();
err.missing_comma = Some(sp);
}
return Err(err.into_diagnostic(self.diagnostic()));
return Err(err.into_diagnostic(self.dcx()));
}
}
_ => {
@ -1837,7 +1837,7 @@ impl<'a> Parser<'a> {
// Make sure an error was emitted (either by recovering an angle bracket,
// or by finding an identifier as the next token), since we're
// going to continue parsing
assert!(self.diagnostic().has_errors().is_some());
assert!(self.dcx().has_errors().is_some());
} else {
return Err(err);
}

View File

@ -114,8 +114,9 @@ impl<'a> Parser<'a> {
NonterminalKind::Item => match self.parse_item(ForceCollect::Yes)? {
Some(item) => NtItem(item),
None => {
return Err(UnexpectedNonterminal::Item(self.token.span)
.into_diagnostic(self.diagnostic()));
return Err(
UnexpectedNonterminal::Item(self.token.span).into_diagnostic(self.dcx())
);
}
},
NonterminalKind::Block => {
@ -127,7 +128,7 @@ impl<'a> Parser<'a> {
Some(s) => NtStmt(P(s)),
None => {
return Err(UnexpectedNonterminal::Statement(self.token.span)
.into_diagnostic(self.diagnostic()));
.into_diagnostic(self.dcx()));
}
},
NonterminalKind::PatParam { .. } | NonterminalKind::PatWithOr => {
@ -163,7 +164,7 @@ impl<'a> Parser<'a> {
span: self.token.span,
token: self.token.clone(),
}
.into_diagnostic(self.diagnostic()));
.into_diagnostic(self.dcx()));
}
NonterminalKind::Path => {
NtPath(P(self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?))
@ -181,7 +182,7 @@ impl<'a> Parser<'a> {
span: self.token.span,
token: self.token.clone(),
}
.into_diagnostic(self.diagnostic()));
.into_diagnostic(self.dcx()));
}
}
};

View File

@ -873,7 +873,7 @@ impl<'a> Parser<'a> {
// will direct us over to `parse_enum_variant()`.
if self.token == token::OpenDelim(Delimiter::Parenthesis) {
return Err(EnumPatternInsteadOfIdentifier { span: self.prev_token.span }
.into_diagnostic(self.diagnostic()));
.into_diagnostic(self.dcx()));
}
Ok(PatKind::Ident(binding_annotation, ident, sub))
@ -987,7 +987,7 @@ impl<'a> Parser<'a> {
// check that a comma comes after every field
if !ate_comma {
let mut err = ExpectedCommaAfterPatternField { span: self.token.span }
.into_diagnostic(self.diagnostic());
.into_diagnostic(self.dcx());
if let Some(mut delayed) = delayed_err {
delayed.emit();
}

View File

@ -123,7 +123,7 @@ impl<'a> Parser<'a> {
self.bump(); // colon
self.diagnostic()
self.dcx()
.struct_span_err(
self.prev_token.span,
"found single colon before projection in qualified path",
@ -326,7 +326,7 @@ impl<'a> Parser<'a> {
.is_nightly_build()
.then_some(()),
}
.into_diagnostic(self.diagnostic());
.into_diagnostic(self.dcx());
}
// Attempt to find places where a missing `>` might belong.
else if let Some(arg) = args