about summary refs log tree commit diff
path: root/clippy_utils
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
commit4dd07f4e4e921df60a41891c8ed9f63d11c5d48a (patch)
tree98ae0378c0d21b61bbed28e54328cb409a511ec3 /clippy_utils
parent8f23de1f4a829ae12822f3476f239458c4d9a65d (diff)
parent0c653d9f91ad8211701ce685b6cb2a2df1253df2 (diff)
downloadrust-4dd07f4e4e921df60a41891c8ed9f63d11c5d48a.tar.gz
rust-4dd07f4e4e921df60a41891c8ed9f63d11c5d48a.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 'clippy_utils')
-rw-r--r--clippy_utils/src/diagnostics.rs18
1 files changed, 12 insertions, 6 deletions
diff --git a/clippy_utils/src/diagnostics.rs b/clippy_utils/src/diagnostics.rs
index dc0a139e3c7..0641d37cd9a 100644
--- a/clippy_utils/src/diagnostics.rs
+++ b/clippy_utils/src/diagnostics.rs
@@ -61,7 +61,8 @@ fn docs_link(diag: &mut Diag<'_, ()>, lint: &'static Lint) {
 /// ```
 pub fn span_lint<T: LintContext>(cx: &T, lint: &'static Lint, sp: impl Into<MultiSpan>, msg: impl Into<DiagMessage>) {
     #[expect(clippy::disallowed_methods)]
-    cx.span_lint(lint, sp, msg.into(), |diag| {
+    cx.span_lint(lint, sp, |diag| {
+        diag.primary_message(msg);
         docs_link(diag, lint);
     });
 }
@@ -109,7 +110,8 @@ pub fn span_lint_and_help<T: LintContext>(
     help: impl Into<SubdiagMessage>,
 ) {
     #[expect(clippy::disallowed_methods)]
-    cx.span_lint(lint, span, msg.into(), |diag| {
+    cx.span_lint(lint, span, |diag| {
+        diag.primary_message(msg);
         if let Some(help_span) = help_span {
             diag.span_help(help_span, help.into());
         } else {
@@ -165,7 +167,8 @@ pub fn span_lint_and_note<T: LintContext>(
     note: impl Into<SubdiagMessage>,
 ) {
     #[expect(clippy::disallowed_methods)]
-    cx.span_lint(lint, span, msg.into(), |diag| {
+    cx.span_lint(lint, span, |diag| {
+        diag.primary_message(msg);
         if let Some(note_span) = note_span {
             diag.span_note(note_span, note.into());
         } else {
@@ -201,7 +204,8 @@ where
     F: FnOnce(&mut Diag<'_, ()>),
 {
     #[expect(clippy::disallowed_methods)]
-    cx.span_lint(lint, sp, msg, |diag| {
+    cx.span_lint(lint, sp, |diag| {
+        diag.primary_message(msg);
         f(diag);
         docs_link(diag, lint);
     });
@@ -233,7 +237,8 @@ where
 /// the `#[allow]` will work.
 pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: impl Into<DiagMessage>) {
     #[expect(clippy::disallowed_methods)]
-    cx.tcx.node_span_lint(lint, hir_id, sp, msg.into(), |diag| {
+    cx.tcx.node_span_lint(lint, hir_id, sp, |diag| {
+        diag.primary_message(msg);
         docs_link(diag, lint);
     });
 }
@@ -271,7 +276,8 @@ pub fn span_lint_hir_and_then(
     f: impl FnOnce(&mut Diag<'_, ()>),
 ) {
     #[expect(clippy::disallowed_methods)]
-    cx.tcx.node_span_lint(lint, hir_id, sp, msg.into(), |diag| {
+    cx.tcx.node_span_lint(lint, hir_id, sp, |diag| {
+        diag.primary_message(msg);
         f(diag);
         docs_link(diag, lint);
     });