Skip to content

Commit 9e1c9eb

Browse files
entry: link to Entry API if can't make a suggestion (#15546)
For #11598 changelog: [`entry`] link to `Entry` API if can't make a suggestion
2 parents 7dd11b8 + cf3f61c commit 9e1c9eb

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

clippy_lints/src/entry.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
1+
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg};
22
use clippy_utils::source::{reindent_multiline, snippet_indent, snippet_with_applicability, snippet_with_context};
33
use clippy_utils::ty::is_copy;
44
use clippy_utils::visitors::for_each_expr;
@@ -194,7 +194,17 @@ impl<'tcx> LateLintPass<'tcx> for HashMapPass {
194194
if let Some(sugg) = sugg {
195195
span_lint_and_sugg(cx, MAP_ENTRY, expr.span, lint_msg, "try", sugg, app);
196196
} else {
197-
span_lint(cx, MAP_ENTRY, expr.span, lint_msg);
197+
span_lint_and_help(
198+
cx,
199+
MAP_ENTRY,
200+
expr.span,
201+
lint_msg,
202+
None,
203+
format!(
204+
"consider using the `Entry` API: https://doc.rust-lang.org/std/collections/struct.{}.html#entry-api",
205+
map_ty.name()
206+
),
207+
);
198208
}
199209
}
200210
}

tests/ui/entry_unfixable.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ LL | | false
1010
LL | | }
1111
| |_____________^
1212
|
13+
= help: consider using the `Entry` API: https://doc.rust-lang.org/std/collections/struct.HashMap.html#entry-api
1314
= note: `-D clippy::map-entry` implied by `-D warnings`
1415
= help: to override `-D warnings` add `#[allow(clippy::map_entry)]`
1516

@@ -24,6 +25,8 @@ LL | | } else {
2425
LL | | hm.insert(key, true);
2526
LL | | }
2627
| |_____^
28+
|
29+
= help: consider using the `Entry` API: https://doc.rust-lang.org/std/collections/struct.HashMap.html#entry-api
2730

2831
error: usage of `contains_key` followed by `insert` on a `HashMap`
2932
--> tests/ui/entry_unfixable.rs:80:13
@@ -36,6 +39,8 @@ LL | | let interner = INTERNER.lock().unwrap();
3639
LL | | return Err(interner.resolve(name).unwrap().to_owned());
3740
LL | | }
3841
| |_____________^
42+
|
43+
= help: consider using the `Entry` API: https://doc.rust-lang.org/std/collections/struct.HashMap.html#entry-api
3944

4045
error: aborting due to 3 previous errors
4146

0 commit comments

Comments
 (0)