rustc_errors: let DiagnosticBuilder::emit
return a "guarantee of emission".
This commit is contained in:
parent
0b9d70cf6d
commit
b7e95dee65
83 changed files with 842 additions and 471 deletions
|
@ -16,7 +16,7 @@ use rustc_ast::{
|
|||
};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_errors::{pluralize, struct_span_err, Diagnostic};
|
||||
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorReported};
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder, Handler, PResult};
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::symbol::{kw, Ident};
|
||||
|
@ -53,7 +53,11 @@ pub enum Error {
|
|||
}
|
||||
|
||||
impl Error {
|
||||
fn span_err(self, sp: impl Into<MultiSpan>, handler: &Handler) -> DiagnosticBuilder<'_> {
|
||||
fn span_err(
|
||||
self,
|
||||
sp: impl Into<MultiSpan>,
|
||||
handler: &Handler,
|
||||
) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||
match self {
|
||||
Error::UselessDocComment => {
|
||||
let mut err = struct_span_err!(
|
||||
|
@ -151,11 +155,19 @@ impl AttemptLocalParseRecovery {
|
|||
}
|
||||
|
||||
impl<'a> Parser<'a> {
|
||||
pub(super) fn span_err<S: Into<MultiSpan>>(&self, sp: S, err: Error) -> DiagnosticBuilder<'a> {
|
||||
pub(super) fn span_err<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
sp: S,
|
||||
err: Error,
|
||||
) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||
err.span_err(sp, self.diagnostic())
|
||||
}
|
||||
|
||||
pub fn struct_span_err<S: Into<MultiSpan>>(&self, sp: S, m: &str) -> DiagnosticBuilder<'a> {
|
||||
pub fn struct_span_err<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
sp: S,
|
||||
m: &str,
|
||||
) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||
self.sess.span_diagnostic.struct_span_err(sp, m)
|
||||
}
|
||||
|
||||
|
@ -171,7 +183,7 @@ impl<'a> Parser<'a> {
|
|||
self.sess.source_map().span_to_snippet(span)
|
||||
}
|
||||
|
||||
pub(super) fn expected_ident_found(&self) -> DiagnosticBuilder<'a> {
|
||||
pub(super) fn expected_ident_found(&self) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||
let mut err = self.struct_span_err(
|
||||
self.token.span,
|
||||
&format!("expected identifier, found {}", super::token_descr(&self.token)),
|
||||
|
@ -717,7 +729,7 @@ impl<'a> Parser<'a> {
|
|||
/// encounter a parse error when encountering the first `,`.
|
||||
pub(super) fn check_mistyped_turbofish_with_multiple_type_params(
|
||||
&mut self,
|
||||
mut e: DiagnosticBuilder<'a>,
|
||||
mut e: DiagnosticBuilder<'a, ErrorReported>,
|
||||
expr: &mut P<Expr>,
|
||||
) -> PResult<'a, ()> {
|
||||
if let ExprKind::Binary(binop, _, _) = &expr.kind {
|
||||
|
@ -1439,7 +1451,7 @@ impl<'a> Parser<'a> {
|
|||
pub(super) fn recover_closing_delimiter(
|
||||
&mut self,
|
||||
tokens: &[TokenKind],
|
||||
mut err: DiagnosticBuilder<'a>,
|
||||
mut err: DiagnosticBuilder<'a, ErrorReported>,
|
||||
) -> PResult<'a, bool> {
|
||||
let mut pos = None;
|
||||
// We want to use the last closing delim that would apply.
|
||||
|
@ -1810,7 +1822,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(super) fn expected_expression_found(&self) -> DiagnosticBuilder<'a> {
|
||||
pub(super) fn expected_expression_found(&self) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||
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);
|
||||
|
@ -2016,7 +2028,7 @@ impl<'a> Parser<'a> {
|
|||
pub fn recover_const_arg(
|
||||
&mut self,
|
||||
start: Span,
|
||||
mut err: DiagnosticBuilder<'a>,
|
||||
mut err: DiagnosticBuilder<'a, ErrorReported>,
|
||||
) -> PResult<'a, GenericArg> {
|
||||
let is_op = AssocOp::from_token(&self.token)
|
||||
.and_then(|op| {
|
||||
|
@ -2096,7 +2108,7 @@ impl<'a> Parser<'a> {
|
|||
pub(super) fn incorrect_move_async_order_found(
|
||||
&self,
|
||||
move_async_span: Span,
|
||||
) -> DiagnosticBuilder<'a> {
|
||||
) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||
let mut err =
|
||||
self.struct_span_err(move_async_span, "the order of `move` and `async` is incorrect");
|
||||
err.span_suggestion_verbose(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue