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

@ -31,7 +31,7 @@ impl AddToDiagnostic for OverruledAttributeSub {
match self {
OverruledAttributeSub::DefaultSource { id } => {
diag.note(fluent::lint_default_source);
diag.set_arg("id", id);
diag.arg("id", id);
}
OverruledAttributeSub::NodeSource { span, reason } => {
diag.span_label(span, fluent::lint_node_source);

View file

@ -1069,7 +1069,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
Some(span.into()),
fluent::lint_unknown_gated_lint,
|lint| {
lint.set_arg("name", lint_id.lint.name_lower());
lint.arg("name", lint_id.lint.name_lower());
lint.note(fluent::lint_note);
rustc_session::parse::add_feature_diagnostics_for_issue(
lint,

View file

@ -5,8 +5,8 @@ use std::num::NonZeroU32;
use crate::errors::RequestedLevel;
use crate::fluent_generated as fluent;
use rustc_errors::{
AddToDiagnostic, Applicability, DecorateLint, DiagnosticMessage, DiagnosticStyledString,
SuggestionStyle,
AddToDiagnostic, Applicability, DecorateLint, Diagnostic, DiagnosticBuilder, DiagnosticMessage,
DiagnosticStyledString, SubdiagnosticMessage, SuggestionStyle,
};
use rustc_hir::def_id::DefId;
use rustc_macros::{LintDiagnostic, Subdiagnostic};
@ -135,7 +135,7 @@ pub struct BuiltinMissingDebugImpl<'a> {
// Needed for def_path_str
impl<'a> DecorateLint<'a, ()> for BuiltinMissingDebugImpl<'_> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
diag.set_arg("debug", self.tcx.def_path_str(self.def_id));
diag.arg("debug", self.tcx.def_path_str(self.def_id));
}
fn msg(&self) -> DiagnosticMessage {
@ -239,7 +239,7 @@ pub struct BuiltinUngatedAsyncFnTrackCaller<'a> {
}
impl<'a> DecorateLint<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
diag.span_label(self.label, fluent::lint_label);
rustc_session::parse::add_feature_diagnostics(
diag,
@ -268,12 +268,9 @@ pub struct SuggestChangingAssocTypes<'a, 'b> {
}
impl AddToDiagnostic for SuggestChangingAssocTypes<'_, '_> {
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
where
F: Fn(
&mut rustc_errors::Diagnostic,
rustc_errors::SubdiagnosticMessage,
) -> rustc_errors::SubdiagnosticMessage,
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
{
// Access to associates types should use `<T as Bound>::Assoc`, which does not need a
// bound. Let's see if this type does that.
@ -281,7 +278,7 @@ impl AddToDiagnostic for SuggestChangingAssocTypes<'_, '_> {
// We use a HIR visitor to walk the type.
use rustc_hir::intravisit::{self, Visitor};
struct WalkAssocTypes<'a> {
err: &'a mut rustc_errors::Diagnostic,
err: &'a mut Diagnostic,
}
impl Visitor<'_> for WalkAssocTypes<'_> {
fn visit_qpath(
@ -326,12 +323,9 @@ pub struct BuiltinTypeAliasGenericBoundsSuggestion {
}
impl AddToDiagnostic for BuiltinTypeAliasGenericBoundsSuggestion {
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
where
F: Fn(
&mut rustc_errors::Diagnostic,
rustc_errors::SubdiagnosticMessage,
) -> rustc_errors::SubdiagnosticMessage,
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
{
diag.multipart_suggestion(
fluent::lint_suggestion,
@ -425,8 +419,8 @@ pub struct BuiltinUnpermittedTypeInit<'a> {
}
impl<'a> DecorateLint<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
diag.set_arg("ty", self.ty);
fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
diag.arg("ty", self.ty);
diag.span_label(self.label, fluent::lint_builtin_unpermitted_type_init_label);
if let InhabitedPredicate::True = self.ty.inhabited_predicate(self.tcx) {
// Only suggest late `MaybeUninit::assume_init` initialization if the type is inhabited.
@ -438,7 +432,7 @@ impl<'a> DecorateLint<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
self.sub.add_to_diagnostic(diag);
}
fn msg(&self) -> rustc_errors::DiagnosticMessage {
fn msg(&self) -> DiagnosticMessage {
self.msg.clone()
}
}
@ -449,12 +443,9 @@ pub struct BuiltinUnpermittedTypeInitSub {
}
impl AddToDiagnostic for BuiltinUnpermittedTypeInitSub {
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
where
F: Fn(
&mut rustc_errors::Diagnostic,
rustc_errors::SubdiagnosticMessage,
) -> rustc_errors::SubdiagnosticMessage,
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
{
let mut err = self.err;
loop {
@ -506,12 +497,9 @@ pub struct BuiltinClashingExternSub<'a> {
}
impl AddToDiagnostic for BuiltinClashingExternSub<'_> {
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
where
F: Fn(
&mut rustc_errors::Diagnostic,
rustc_errors::SubdiagnosticMessage,
) -> rustc_errors::SubdiagnosticMessage,
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
{
let mut expected_str = DiagnosticStyledString::new();
expected_str.push(self.expected.fn_sig(self.tcx).to_string(), false);
@ -779,12 +767,9 @@ pub struct HiddenUnicodeCodepointsDiagLabels {
}
impl AddToDiagnostic for HiddenUnicodeCodepointsDiagLabels {
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
where
F: Fn(
&mut rustc_errors::Diagnostic,
rustc_errors::SubdiagnosticMessage,
) -> rustc_errors::SubdiagnosticMessage,
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
{
for (c, span) in self.spans {
diag.span_label(span, format!("{c:?}"));
@ -799,12 +784,9 @@ pub enum HiddenUnicodeCodepointsDiagSub {
// Used because of multiple multipart_suggestion and note
impl AddToDiagnostic for HiddenUnicodeCodepointsDiagSub {
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
where
F: Fn(
&mut rustc_errors::Diagnostic,
rustc_errors::SubdiagnosticMessage,
) -> rustc_errors::SubdiagnosticMessage,
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
{
match self {
HiddenUnicodeCodepointsDiagSub::Escape { spans } => {
@ -830,7 +812,7 @@ impl AddToDiagnostic for HiddenUnicodeCodepointsDiagSub {
// FIXME: in other suggestions we've reversed the inner spans of doc comments. We
// should do the same here to provide the same good suggestions as we do for
// literals above.
diag.set_arg(
diag.arg(
"escaped",
spans
.into_iter()
@ -953,12 +935,9 @@ pub struct NonBindingLetSub {
}
impl AddToDiagnostic for NonBindingLetSub {
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
where
F: Fn(
&mut rustc_errors::Diagnostic,
rustc_errors::SubdiagnosticMessage,
) -> rustc_errors::SubdiagnosticMessage,
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
{
diag.span_suggestion_verbose(
self.suggestion,
@ -1147,8 +1126,8 @@ pub struct NonFmtPanicUnused {
// Used because of two suggestions based on one Option<Span>
impl<'a> DecorateLint<'a, ()> for NonFmtPanicUnused {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
diag.set_arg("count", self.count);
fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
diag.arg("count", self.count);
diag.note(fluent::lint_note);
if let Some(span) = self.suggestion {
diag.span_suggestion(
@ -1166,7 +1145,7 @@ impl<'a> DecorateLint<'a, ()> for NonFmtPanicUnused {
}
}
fn msg(&self) -> rustc_errors::DiagnosticMessage {
fn msg(&self) -> DiagnosticMessage {
fluent::lint_non_fmt_panic_unused
}
}
@ -1224,12 +1203,9 @@ pub enum NonSnakeCaseDiagSub {
}
impl AddToDiagnostic for NonSnakeCaseDiagSub {
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
where
F: Fn(
&mut rustc_errors::Diagnostic,
rustc_errors::SubdiagnosticMessage,
) -> rustc_errors::SubdiagnosticMessage,
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
{
match self {
NonSnakeCaseDiagSub::Label { span } => {
@ -1342,12 +1318,12 @@ pub struct DropTraitConstraintsDiag<'a> {
// Needed for def_path_str
impl<'a> DecorateLint<'a, ()> for DropTraitConstraintsDiag<'_> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
diag.set_arg("predicate", self.predicate);
diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id));
fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
diag.arg("predicate", self.predicate);
diag.arg("needs_drop", self.tcx.def_path_str(self.def_id));
}
fn msg(&self) -> rustc_errors::DiagnosticMessage {
fn msg(&self) -> DiagnosticMessage {
fluent::lint_drop_trait_constraints
}
}
@ -1359,11 +1335,11 @@ pub struct DropGlue<'a> {
// Needed for def_path_str
impl<'a> DecorateLint<'a, ()> for DropGlue<'_> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id));
fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
diag.arg("needs_drop", self.tcx.def_path_str(self.def_id));
}
fn msg(&self) -> rustc_errors::DiagnosticMessage {
fn msg(&self) -> DiagnosticMessage {
fluent::lint_drop_glue
}
}
@ -1423,12 +1399,9 @@ pub enum OverflowingBinHexSign {
}
impl AddToDiagnostic for OverflowingBinHexSign {
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
where
F: Fn(
&mut rustc_errors::Diagnostic,
rustc_errors::SubdiagnosticMessage,
) -> rustc_errors::SubdiagnosticMessage,
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
{
match self {
OverflowingBinHexSign::Positive => {
@ -1633,9 +1606,9 @@ pub struct ImproperCTypes<'a> {
// Used because of the complexity of Option<DiagnosticMessage>, DiagnosticMessage, and Option<Span>
impl<'a> DecorateLint<'a, ()> for ImproperCTypes<'_> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
diag.set_arg("ty", self.ty);
diag.set_arg("desc", self.desc);
fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
diag.arg("ty", self.ty);
diag.arg("desc", self.desc);
diag.span_label(self.label, fluent::lint_label);
if let Some(help) = self.help {
diag.help(help);
@ -1646,7 +1619,7 @@ impl<'a> DecorateLint<'a, ()> for ImproperCTypes<'_> {
}
}
fn msg(&self) -> rustc_errors::DiagnosticMessage {
fn msg(&self) -> DiagnosticMessage {
fluent::lint_improper_ctypes
}
}
@ -1776,10 +1749,10 @@ pub enum UnusedDefSuggestion {
// Needed because of def_path_str
impl<'a> DecorateLint<'a, ()> for UnusedDef<'_, '_> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
diag.set_arg("pre", self.pre);
diag.set_arg("post", self.post);
diag.set_arg("def", self.cx.tcx.def_path_str(self.def_id));
fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
diag.arg("pre", self.pre);
diag.arg("post", self.post);
diag.arg("def", self.cx.tcx.def_path_str(self.def_id));
// check for #[must_use = "..."]
if let Some(note) = self.note {
diag.note(note.to_string());
@ -1789,7 +1762,7 @@ impl<'a> DecorateLint<'a, ()> for UnusedDef<'_, '_> {
}
}
fn msg(&self) -> rustc_errors::DiagnosticMessage {
fn msg(&self) -> DiagnosticMessage {
fluent::lint_unused_def
}
}
@ -1859,14 +1832,14 @@ pub struct AsyncFnInTraitDiag {
}
impl<'a> DecorateLint<'a, ()> for AsyncFnInTraitDiag {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) {
fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
diag.note(fluent::lint_note);
if let Some(sugg) = self.sugg {
diag.multipart_suggestion(fluent::lint_suggestion, sugg, Applicability::MaybeIncorrect);
}
}
fn msg(&self) -> rustc_errors::DiagnosticMessage {
fn msg(&self) -> DiagnosticMessage {
fluent::lint_async_fn_in_trait
}
}

View file

@ -121,7 +121,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
#[allow(rustc::diagnostic_outside_of_impl)]
cx.struct_span_lint(NON_FMT_PANICS, arg_span, fluent::lint_non_fmt_panic, |lint| {
lint.set_arg("name", symbol);
lint.arg("name", symbol);
lint.note(fluent::lint_note);
lint.note(fluent::lint_more_info_note);
if !is_arg_inside_call(arg_span, span) {
@ -180,7 +180,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
fmt_applicability,
);
} else if suggest_debug {
lint.set_arg("ty", ty);
lint.arg("ty", ty);
lint.span_suggestion_verbose(
arg_span.shrink_to_lo(),
fluent::lint_debug_suggestion,
@ -191,7 +191,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
if suggest_panic_any {
if let Some((open, close, del)) = find_delimiters(cx, span) {
lint.set_arg("already_suggested", suggest_display || suggest_debug);
lint.arg("already_suggested", suggest_display || suggest_debug);
lint.multipart_suggestion(
fluent::lint_panic_suggestion,
if del == '(' {