Rollup merge of #119171 - nnethercote:cleanup-errors-4, r=compiler-errors

Cleanup error handlers: round 4

More `rustc_errors` cleanups. A sequel to #118933.

r? `@compiler-errors`
This commit is contained in:
Michael Goulet 2023-12-22 21:41:03 -05:00 committed by GitHub
commit e0d7a72c46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
84 changed files with 611 additions and 946 deletions

View file

@ -1118,15 +1118,12 @@ impl<'a> ExtCtxt<'a> {
&self,
sp: S,
msg: impl Into<DiagnosticMessage>,
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
) -> DiagnosticBuilder<'a> {
self.sess.dcx().struct_span_err(sp, msg)
}
#[track_caller]
pub fn create_err(
&self,
err: impl IntoDiagnostic<'a>,
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
pub fn create_err(&self, err: impl IntoDiagnostic<'a>) -> DiagnosticBuilder<'a> {
self.sess.create_err(err)
}
@ -1230,7 +1227,7 @@ pub fn expr_to_spanned_string<'a>(
cx: &'a mut ExtCtxt<'_>,
expr: P<ast::Expr>,
err_msg: &'static str,
) -> Result<(Symbol, ast::StrStyle, Span), Option<(DiagnosticBuilder<'a, ErrorGuaranteed>, bool)>> {
) -> Result<(Symbol, ast::StrStyle, Span), Option<(DiagnosticBuilder<'a>, bool)>> {
// Perform eager expansion on the expression.
// We want to be able to handle e.g., `concat!("foo", "bar")`.
let expr = cx.expander().fully_expand_fragment(AstFragment::Expr(expr)).make_expr();

View file

@ -215,7 +215,7 @@ impl<'matcher> Tracker<'matcher> for FailureForwarder {
}
pub(super) fn emit_frag_parse_err(
mut e: DiagnosticBuilder<'_, rustc_errors::ErrorGuaranteed>,
mut e: DiagnosticBuilder<'_>,
parser: &Parser<'_>,
orig_parser: &mut Parser<'_>,
site_span: Span,
@ -224,11 +224,11 @@ pub(super) fn emit_frag_parse_err(
) {
// FIXME(davidtwco): avoid depending on the error message text
if parser.token == token::Eof
&& let DiagnosticMessage::Str(message) = &e.message[0].0
&& let DiagnosticMessage::Str(message) = &e.messages[0].0
&& message.ends_with(", found `<eof>`")
{
let msg = &e.message[0];
e.message[0] = (
let msg = &e.messages[0];
e.messages[0] = (
DiagnosticMessage::from(format!(
"macro expansion ends with an incomplete expression: {}",
message.replace(", found `<eof>`", ""),

View file

@ -9,8 +9,8 @@ use rustc_ast::mut_visit::{self, MutVisitor};
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::DiagnosticBuilder;
use rustc_errors::{pluralize, PResult};
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
use rustc_span::hygiene::{LocalExpnId, Transparency};
use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent};
use rustc_span::Span;
@ -528,7 +528,7 @@ fn out_of_bounds_err<'a>(
max: usize,
span: Span,
ty: &str,
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
) -> DiagnosticBuilder<'a> {
let msg = if max == 0 {
format!(
"meta-variable expression `{ty}` with depth parameter \

View file

@ -43,7 +43,7 @@ pub enum ModError<'a> {
ModInBlock(Option<Ident>),
FileNotFound(Ident, PathBuf, PathBuf),
MultipleCandidates(Ident, PathBuf, PathBuf),
ParserError(DiagnosticBuilder<'a, ErrorGuaranteed>),
ParserError(DiagnosticBuilder<'a>),
}
pub(crate) fn parse_external_mod(

View file

@ -499,12 +499,7 @@ impl server::FreeFunctions for Rustc<'_, '_> {
rustc_errors::Diagnostic::new(diagnostic.level.to_internal(), diagnostic.message);
diag.set_span(MultiSpan::from_spans(diagnostic.spans));
for child in diagnostic.children {
diag.sub(
child.level.to_internal(),
child.message,
MultiSpan::from_spans(child.spans),
None,
);
diag.sub(child.level.to_internal(), child.message, MultiSpan::from_spans(child.spans));
}
self.sess().dcx.emit_diagnostic(diag);
}