Auto merge of #125410 - fmease:adj-lint-diag-api, r=nnethercote
[perf] Delay the construction of early lint diag structs
Attacks some of the perf regressions from https://github.com/rust-lang/rust/pull/124417#issuecomment-2123700666.
See individual commits for details. The first three commits are not strictly necessary.
However, the 2nd one (06bc4fc671
, *Remove `LintDiagnostic::msg`*) makes the main change way nicer to implement.
It's also pretty sweet on its own if I may say so myself.
This commit is contained in:
commit
b582f807fa
50 changed files with 598 additions and 749 deletions
|
@ -145,12 +145,9 @@ pub struct BuiltinMissingDebugImpl<'a> {
|
|||
// Needed for def_path_str
|
||||
impl<'a> LintDiagnostic<'a, ()> for BuiltinMissingDebugImpl<'_> {
|
||||
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) {
|
||||
diag.primary_message(fluent::lint_builtin_missing_debug_impl);
|
||||
diag.arg("debug", self.tcx.def_path_str(self.def_id));
|
||||
}
|
||||
|
||||
fn msg(&self) -> DiagMessage {
|
||||
fluent::lint_builtin_missing_debug_impl
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
|
@ -250,6 +247,7 @@ pub struct BuiltinUngatedAsyncFnTrackCaller<'a> {
|
|||
|
||||
impl<'a> LintDiagnostic<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> {
|
||||
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
||||
diag.primary_message(fluent::lint_ungated_async_fn_track_caller);
|
||||
diag.span_label(self.label, fluent::lint_label);
|
||||
rustc_session::parse::add_feature_diagnostics(
|
||||
diag,
|
||||
|
@ -257,10 +255,6 @@ impl<'a> LintDiagnostic<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> {
|
|||
sym::async_fn_track_caller,
|
||||
);
|
||||
}
|
||||
|
||||
fn msg(&self) -> DiagMessage {
|
||||
fluent::lint_ungated_async_fn_track_caller
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
|
@ -432,6 +426,7 @@ pub struct BuiltinUnpermittedTypeInit<'a> {
|
|||
|
||||
impl<'a> LintDiagnostic<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
|
||||
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
||||
diag.primary_message(self.msg);
|
||||
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) {
|
||||
|
@ -443,10 +438,6 @@ impl<'a> LintDiagnostic<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
|
|||
}
|
||||
self.sub.add_to_diag(diag);
|
||||
}
|
||||
|
||||
fn msg(&self) -> DiagMessage {
|
||||
self.msg.clone()
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(davidtwco): make translatable
|
||||
|
@ -1169,6 +1160,7 @@ pub struct NonFmtPanicUnused {
|
|||
// Used because of two suggestions based on one Option<Span>
|
||||
impl<'a> LintDiagnostic<'a, ()> for NonFmtPanicUnused {
|
||||
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
||||
diag.primary_message(fluent::lint_non_fmt_panic_unused);
|
||||
diag.arg("count", self.count);
|
||||
diag.note(fluent::lint_note);
|
||||
if let Some(span) = self.suggestion {
|
||||
|
@ -1186,10 +1178,6 @@ impl<'a> LintDiagnostic<'a, ()> for NonFmtPanicUnused {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn msg(&self) -> DiagMessage {
|
||||
fluent::lint_non_fmt_panic_unused
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
|
@ -1411,13 +1399,10 @@ pub struct DropTraitConstraintsDiag<'a> {
|
|||
// Needed for def_path_str
|
||||
impl<'a> LintDiagnostic<'a, ()> for DropTraitConstraintsDiag<'_> {
|
||||
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
||||
diag.primary_message(fluent::lint_drop_trait_constraints);
|
||||
diag.arg("predicate", self.predicate);
|
||||
diag.arg("needs_drop", self.tcx.def_path_str(self.def_id));
|
||||
}
|
||||
|
||||
fn msg(&self) -> DiagMessage {
|
||||
fluent::lint_drop_trait_constraints
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DropGlue<'a> {
|
||||
|
@ -1428,12 +1413,9 @@ pub struct DropGlue<'a> {
|
|||
// Needed for def_path_str
|
||||
impl<'a> LintDiagnostic<'a, ()> for DropGlue<'_> {
|
||||
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
||||
diag.primary_message(fluent::lint_drop_glue);
|
||||
diag.arg("needs_drop", self.tcx.def_path_str(self.def_id));
|
||||
}
|
||||
|
||||
fn msg(&self) -> DiagMessage {
|
||||
fluent::lint_drop_glue
|
||||
}
|
||||
}
|
||||
|
||||
// types.rs
|
||||
|
@ -1711,6 +1693,7 @@ pub struct ImproperCTypes<'a> {
|
|||
// Used because of the complexity of Option<DiagMessage>, DiagMessage, and Option<Span>
|
||||
impl<'a> LintDiagnostic<'a, ()> for ImproperCTypes<'_> {
|
||||
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
||||
diag.primary_message(fluent::lint_improper_ctypes);
|
||||
diag.arg("ty", self.ty);
|
||||
diag.arg("desc", self.desc);
|
||||
diag.span_label(self.label, fluent::lint_label);
|
||||
|
@ -1722,10 +1705,6 @@ impl<'a> LintDiagnostic<'a, ()> for ImproperCTypes<'_> {
|
|||
diag.span_note(note, fluent::lint_note);
|
||||
}
|
||||
}
|
||||
|
||||
fn msg(&self) -> DiagMessage {
|
||||
fluent::lint_improper_ctypes
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
|
@ -1854,6 +1833,7 @@ pub enum UnusedDefSuggestion {
|
|||
// Needed because of def_path_str
|
||||
impl<'a> LintDiagnostic<'a, ()> for UnusedDef<'_, '_> {
|
||||
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
||||
diag.primary_message(fluent::lint_unused_def);
|
||||
diag.arg("pre", self.pre);
|
||||
diag.arg("post", self.post);
|
||||
diag.arg("def", self.cx.tcx.def_path_str(self.def_id));
|
||||
|
@ -1865,10 +1845,6 @@ impl<'a> LintDiagnostic<'a, ()> for UnusedDef<'_, '_> {
|
|||
diag.subdiagnostic(diag.dcx, sugg);
|
||||
}
|
||||
}
|
||||
|
||||
fn msg(&self) -> DiagMessage {
|
||||
fluent::lint_unused_def
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
|
@ -1937,15 +1913,12 @@ pub struct AsyncFnInTraitDiag {
|
|||
|
||||
impl<'a> LintDiagnostic<'a, ()> for AsyncFnInTraitDiag {
|
||||
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
||||
diag.primary_message(fluent::lint_async_fn_in_trait);
|
||||
diag.note(fluent::lint_note);
|
||||
if let Some(sugg) = self.sugg {
|
||||
diag.multipart_suggestion(fluent::lint_suggestion, sugg, Applicability::MaybeIncorrect);
|
||||
}
|
||||
}
|
||||
|
||||
fn msg(&self) -> DiagMessage {
|
||||
fluent::lint_async_fn_in_trait
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
|
@ -2273,10 +2246,8 @@ pub struct UnstableFeature {
|
|||
}
|
||||
|
||||
impl<'a> LintDiagnostic<'a, ()> for UnstableFeature {
|
||||
fn decorate_lint<'b>(self, _diag: &'b mut Diag<'a, ()>) {}
|
||||
|
||||
fn msg(&self) -> DiagMessage {
|
||||
self.msg.clone()
|
||||
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
||||
diag.primary_message(self.msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2738,12 +2709,9 @@ pub struct AmbiguousGlobImports {
|
|||
|
||||
impl<'a, G: EmissionGuarantee> LintDiagnostic<'a, G> for AmbiguousGlobImports {
|
||||
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>) {
|
||||
diag.primary_message(self.ambiguity.msg.clone());
|
||||
rustc_errors::report_ambiguity_error(diag, self.ambiguity);
|
||||
}
|
||||
|
||||
fn msg(&self) -> DiagMessage {
|
||||
DiagMessage::Str(self.ambiguity.msg.clone().into())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue