Skip to content

Commit 706d519

Browse files
committed
rephrase the note
1 parent ef98089 commit 706d519

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

clippy_lints_internal/src/repeated_is_diagnostic_item.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ declare_tool_lint! {
3535
}
3636
declare_lint_pass!(RepeatedIsDiagnosticItem => [REPEATED_IS_DIAGNOSTIC_ITEM]);
3737

38+
const NOTE: &str = "each call performs the same compiler query -- it's faster to query once, and reuse the results";
39+
3840
impl LateLintPass<'_> for RepeatedIsDiagnosticItem {
3941
#[expect(clippy::too_many_lines)]
4042
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
@@ -57,7 +59,7 @@ impl LateLintPass<'_> for RepeatedIsDiagnosticItem {
5759
expr.span,
5860
format!("repeated calls to `{recv_ty}::is_diag_item`"),
5961
|diag| {
60-
diag.note("this calls `TyCtxt::is_diagnostic_item` internally, which is expensive");
62+
diag.note(NOTE);
6163

6264
let mut app = Applicability::MachineApplicable;
6365
let cx_str = snippet_with_applicability(cx, cx1.span, "_", &mut app);
@@ -87,7 +89,7 @@ impl LateLintPass<'_> for RepeatedIsDiagnosticItem {
8789
expr.span,
8890
"repeated calls to `TyCtxt::is_diagnostic_item`",
8991
|diag| {
90-
diag.note("this calls an expensive compiler query");
92+
diag.note(NOTE);
9193

9294
let mut app = Applicability::MachineApplicable;
9395
let tcx = snippet_with_applicability(cx, tcx1.span, "_", &mut app);
@@ -127,7 +129,7 @@ impl LateLintPass<'_> for RepeatedIsDiagnosticItem {
127129
expr.span,
128130
format!("repeated calls to `{recv_ty}::is_diag_item`"),
129131
|diag| {
130-
diag.note("this calls `TyCtxt::is_diagnostic_item` internally, which is expensive");
132+
diag.note(NOTE);
131133

132134
let mut app = Applicability::MachineApplicable;
133135
let cx_str = snippet_with_applicability(cx, cx1.span, "_", &mut app);
@@ -157,7 +159,7 @@ impl LateLintPass<'_> for RepeatedIsDiagnosticItem {
157159
expr.span,
158160
"repeated calls to `TyCtxt::is_diagnostic_item`",
159161
|diag| {
160-
diag.note("this calls an expensive compiler query");
162+
diag.note(NOTE);
161163

162164
let mut app = Applicability::MachineApplicable;
163165
let tcx = snippet_with_applicability(cx, tcx1.span, "_", &mut app);

tests/ui-internal/repeated_is_diagnostic_item.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: repeated calls to `Ty::is_diag_item`
44
LL | let _ = ty.is_diag_item(cx, sym::Option) || ty.is_diag_item(cx, sym::Result);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: this calls `TyCtxt::is_diagnostic_item` internally, which is expensive
7+
= note: each call performs the same compiler query -- it's faster to query once, and reuse the results
88
= note: `-D clippy::repeated-is-diagnostic-item` implied by `-D warnings`
99
= help: to override `-D warnings` add `#[allow(clippy::repeated_is_diagnostic_item)]`
1010
help: call `Ty::opt_diag_name`, and reuse the results
@@ -19,7 +19,7 @@ error: repeated calls to `Ty::is_diag_item`
1919
LL | let _ = !ty.is_diag_item(cx, sym::Option) && !ty.is_diag_item(cx, sym::Result);
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2121
|
22-
= note: this calls `TyCtxt::is_diagnostic_item` internally, which is expensive
22+
= note: each call performs the same compiler query -- it's faster to query once, and reuse the results
2323
help: call `Ty::opt_diag_name`, and reuse the results
2424
|
2525
LL - let _ = !ty.is_diag_item(cx, sym::Option) && !ty.is_diag_item(cx, sym::Result);
@@ -32,7 +32,7 @@ error: repeated calls to `AdtDef::is_diag_item`
3232
LL | let _ = adt_def.is_diag_item(cx, sym::Option) || adt_def.is_diag_item(cx, sym::Result);
3333
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3434
|
35-
= note: this calls `TyCtxt::is_diagnostic_item` internally, which is expensive
35+
= note: each call performs the same compiler query -- it's faster to query once, and reuse the results
3636
help: call `AdtDef::opt_diag_name`, and reuse the results
3737
|
3838
LL - let _ = adt_def.is_diag_item(cx, sym::Option) || adt_def.is_diag_item(cx, sym::Result);
@@ -45,7 +45,7 @@ error: repeated calls to `AdtDef::is_diag_item`
4545
LL | let _ = !adt_def.is_diag_item(cx, sym::Option) && !adt_def.is_diag_item(cx, sym::Result);
4646
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4747
|
48-
= note: this calls `TyCtxt::is_diagnostic_item` internally, which is expensive
48+
= note: each call performs the same compiler query -- it's faster to query once, and reuse the results
4949
help: call `AdtDef::opt_diag_name`, and reuse the results
5050
|
5151
LL - let _ = !adt_def.is_diag_item(cx, sym::Option) && !adt_def.is_diag_item(cx, sym::Result);
@@ -58,7 +58,7 @@ error: repeated calls to `TyCtxt::is_diagnostic_item`
5858
LL | let _ = cx.tcx.is_diagnostic_item(sym::Option, did) || cx.tcx.is_diagnostic_item(sym::Result, did);
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6060
|
61-
= note: this calls an expensive compiler query
61+
= note: each call performs the same compiler query -- it's faster to query once, and reuse the results
6262
help: call `TyCtxt::get_diagnostic_name`, and reuse the results
6363
|
6464
LL - let _ = cx.tcx.is_diagnostic_item(sym::Option, did) || cx.tcx.is_diagnostic_item(sym::Result, did);
@@ -71,7 +71,7 @@ error: repeated calls to `TyCtxt::is_diagnostic_item`
7171
LL | let _ = !cx.tcx.is_diagnostic_item(sym::Option, did) && !cx.tcx.is_diagnostic_item(sym::Result, did);
7272
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7373
|
74-
= note: this calls an expensive compiler query
74+
= note: each call performs the same compiler query -- it's faster to query once, and reuse the results
7575
help: call `TyCtxt::get_diagnostic_name`, and reuse the results
7676
|
7777
LL - let _ = !cx.tcx.is_diagnostic_item(sym::Option, did) && !cx.tcx.is_diagnostic_item(sym::Result, did);

0 commit comments

Comments
 (0)