summary refs log tree commit diff
path: root/compiler/rustc_middle/src/middle
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-05-27 08:44:12 +0000
committerbors <bors@rust-lang.org>2024-05-27 08:44:12 +0000
commitb582f807fae230b22ac126ff1d8a13262bb099ba (patch)
tree861b8cb9ffe0461d39a824e74a44cc36c2ffa5c2 /compiler/rustc_middle/src/middle
parentfec98b3bbc94b54a0b3085d004708aabcc48081a (diff)
parent37bf2d2dabdbdce9473b0fed1708fcbf31ba9c1a (diff)
downloadrust-b582f807fae230b22ac126ff1d8a13262bb099ba.tar.gz
rust-b582f807fae230b22ac126ff1d8a13262bb099ba.zip
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 (06bc4fc67145e3a7be9b5a2cf2b5968cef36e587, *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.
Diffstat (limited to 'compiler/rustc_middle/src/middle')
-rw-r--r--compiler/rustc_middle/src/middle/stability.rs21
1 files changed, 10 insertions, 11 deletions
diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs
index a377e35b2e9..8cf1bedf0da 100644
--- a/compiler/rustc_middle/src/middle/stability.rs
+++ b/compiler/rustc_middle/src/middle/stability.rs
@@ -157,6 +157,13 @@ pub struct Deprecated {
 
 impl<'a, G: EmissionGuarantee> rustc_errors::LintDiagnostic<'a, G> for Deprecated {
     fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>) {
+        diag.primary_message(match &self.since_kind {
+            DeprecatedSinceKind::InEffect => crate::fluent_generated::middle_deprecated,
+            DeprecatedSinceKind::InFuture => crate::fluent_generated::middle_deprecated_in_future,
+            DeprecatedSinceKind::InVersion(_) => {
+                crate::fluent_generated::middle_deprecated_in_version
+            }
+        });
         diag.arg("kind", self.kind);
         diag.arg("path", self.path);
         if let DeprecatedSinceKind::InVersion(version) = self.since_kind {
@@ -172,16 +179,6 @@ impl<'a, G: EmissionGuarantee> rustc_errors::LintDiagnostic<'a, G> for Deprecate
             diag.subdiagnostic(diag.dcx, sub);
         }
     }
-
-    fn msg(&self) -> rustc_errors::DiagMessage {
-        match &self.since_kind {
-            DeprecatedSinceKind::InEffect => crate::fluent_generated::middle_deprecated,
-            DeprecatedSinceKind::InFuture => crate::fluent_generated::middle_deprecated_in_future,
-            DeprecatedSinceKind::InVersion(_) => {
-                crate::fluent_generated::middle_deprecated_in_version
-            }
-        }
-    }
 }
 
 fn deprecated_since_kind(is_in_effect: bool, since: DeprecatedSince) -> DeprecatedSinceKind {
@@ -598,7 +595,9 @@ impl<'tcx> TyCtxt<'tcx> {
         unmarked: impl FnOnce(Span, DefId),
     ) -> bool {
         let soft_handler = |lint, span, msg: String| {
-            self.node_span_lint(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, msg, |_| {})
+            self.node_span_lint(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, |lint| {
+                lint.primary_message(msg);
+            })
         };
         let eval_result =
             self.eval_stability_allow_unstable(def_id, id, span, method_span, allow_unstable);