1
Fork 0

Rollup merge of #119538 - nnethercote:cleanup-errors-5, r=compiler-errors

Cleanup error handlers: round 5

More rustc_errors cleanups. A sequel to https://github.com/rust-lang/rust/pull/119171.

r? ````@compiler-errors````
This commit is contained in:
Michael Goulet 2024-01-05 10:57:21 -05:00 committed by GitHub
commit f361b591ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
57 changed files with 369 additions and 464 deletions

View file

@ -1065,8 +1065,8 @@ impl<'a> IntoDiagnostic<'a> for ExpectedIdentifier {
None => fluent::parse_expected_identifier_found_str,
},
);
diag.set_span(self.span);
diag.set_arg("token", self.token);
diag.span(self.span);
diag.arg("token", self.token);
if let Some(sugg) = self.suggest_raw {
sugg.add_to_diagnostic(&mut diag);
@ -1123,8 +1123,8 @@ impl<'a> IntoDiagnostic<'a> for ExpectedSemi {
None => fluent::parse_expected_semi_found_str,
},
);
diag.set_span(self.span);
diag.set_arg("token", self.token);
diag.span(self.span);
diag.arg("token", self.token);
if let Some(unexpected_token_label) = self.unexpected_token_label {
diag.span_label(unexpected_token_label, fluent::parse_label_unexpected_token);

View file

@ -7,9 +7,7 @@ use rustc_ast::ast::{self, AttrStyle};
use rustc_ast::token::{self, CommentKind, Delimiter, Token, TokenKind};
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::util::unicode::contains_text_flow_control_chars;
use rustc_errors::{
error_code, Applicability, DiagCtxt, Diagnostic, DiagnosticBuilder, FatalAbort, StashKey,
};
use rustc_errors::{error_code, Applicability, DiagCtxt, Diagnostic, StashKey};
use rustc_lexer::unescape::{self, EscapeError, Mode};
use rustc_lexer::{Base, DocStyle, RawStrError};
use rustc_lexer::{Cursor, LiteralKind};
@ -252,7 +250,7 @@ impl<'a> StringReader<'a> {
if starts_with_number {
let span = self.mk_sp(start, self.pos);
let mut diag = self.dcx().struct_err("lifetimes cannot start with a number");
diag.set_span(span);
diag.span(span);
diag.stash(span, StashKey::LifetimeIsChar);
}
let ident = Symbol::intern(lifetime_name);
@ -344,18 +342,6 @@ impl<'a> StringReader<'a> {
token::Ident(sym, false)
}
fn struct_fatal_span_char(
&self,
from_pos: BytePos,
to_pos: BytePos,
m: &str,
c: char,
) -> DiagnosticBuilder<'a, FatalAbort> {
self.sess
.dcx
.struct_span_fatal(self.mk_sp(from_pos, to_pos), format!("{}: {}", m, escaped_char(c)))
}
/// Detect usages of Unicode codepoints changing the direction of the text on screen and loudly
/// complain about it.
fn lint_unicode_text_flow(&self, start: BytePos) {
@ -568,13 +554,16 @@ impl<'a> StringReader<'a> {
}
fn report_non_started_raw_string(&self, start: BytePos, bad_char: char) -> ! {
self.struct_fatal_span_char(
start,
self.pos,
"found invalid character; only `#` is allowed in raw string delimitation",
bad_char,
)
.emit()
self.sess
.dcx
.struct_span_fatal(
self.mk_sp(start, self.pos),
format!(
"found invalid character; only `#` is allowed in raw string delimitation: {}",
escaped_char(bad_char)
),
)
.emit()
}
fn report_unterminated_raw_string(

View file

@ -154,7 +154,7 @@ fn try_file_to_source_file(
let msg = format!("couldn't read {}: {}", path.display(), e);
let mut diag = Diagnostic::new(Level::Fatal, msg);
if let Some(sp) = spanopt {
diag.set_span(sp);
diag.span(sp);
}
diag
})

View file

@ -174,7 +174,7 @@ impl<'a> Parser<'a> {
) {
Ok(Some(item)) => {
// FIXME(#100717)
err.set_arg("item", item.kind.descr());
err.arg("item", item.kind.descr());
err.span_label(item.span, fluent::parse_label_does_not_annotate_this);
err.span_suggestion_verbose(
replacement_span,

View file

@ -846,7 +846,7 @@ impl<'a> Parser<'a> {
) =>
{
let n_hashes: u8 = *n_hashes;
err.set_primary_message("too many `#` when terminating raw string");
err.primary_message("too many `#` when terminating raw string");
let str_span = self.prev_token.span;
let mut span = self.token.span;
let mut count = 0;
@ -857,7 +857,7 @@ impl<'a> Parser<'a> {
self.bump();
count += 1;
}
err.set_span(span);
err.span(span);
err.span_suggestion(
span,
format!("remove the extra `#`{}", pluralize!(count)),

View file

@ -925,9 +925,8 @@ impl<'a> Parser<'a> {
});
}
expect_err.set_primary_message(
"closure bodies that contain statements must be surrounded by braces",
);
expect_err
.primary_message("closure bodies that contain statements must be surrounded by braces");
let preceding_pipe_span = closure_spans.closing_pipe;
let following_token_span = self.token.span;
@ -951,7 +950,7 @@ impl<'a> Parser<'a> {
);
expect_err.span_note(second_note, "the closure body may be incorrectly delimited");
expect_err.set_span(vec![preceding_pipe_span, following_token_span]);
expect_err.span(vec![preceding_pipe_span, following_token_span]);
let opening_suggestion_str = " {".to_string();
let closing_suggestion_str = "}".to_string();