Skip to content

Commit 609541b

Browse files
author
Yusuf Raji
committed
Fix single_option_map lint emission
1 parent 009f955 commit 609541b

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

clippy_lints/src/single_option_map.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::diagnostics::span_lint;
1+
use clippy_utils::diagnostics::span_lint_and_help;
22
use clippy_utils::peel_blocks;
33
use clippy_utils::ty::is_type_diagnostic_item;
44
use rustc_hir::def_id::LocalDefId;
@@ -57,11 +57,13 @@ impl<'tcx> LateLintPass<'tcx> for SingleOptionMap {
5757
&& is_type_diagnostic_item(cx, callee_type, sym::Option)
5858
&& let ExprKind::Path(_path) = callee.kind
5959
{
60-
span_lint(
60+
span_lint_and_help(
6161
cx,
6262
SINGLE_OPTION_MAP,
6363
span,
64-
"mapping over single function argument of `Option<T>`, to return `Option<T>`, can be best expressed by applying the map outside of the function.",
64+
"`fn` that only maps over argument",
65+
None,
66+
"move the `.map` to the caller or to an `_opt` function",
6567
);
6668
}
6769
}

tests/ui/single_option_map.stderr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
error: mapping over single function argument of `Option<T>`, to return `Option<T>`, can be best expressed by applying the map outside of the function.
1+
error: `fn` that only maps over argument
22
--> tests/ui/single_option_map.rs:3:1
33
|
44
LL | / fn h(arg: Option<u32>) -> Option<u32> {
55
LL | | arg.map(|x| x * 2)
66
LL | | }
77
| |_^
88
|
9+
= help: move the `.map` to the caller or to an `_opt` function
910
= note: `-D clippy::single-option-map` implied by `-D warnings`
1011
= help: to override `-D warnings` add `#[allow(clippy::single_option_map)]`
1112

12-
error: mapping over single function argument of `Option<T>`, to return `Option<T>`, can be best expressed by applying the map outside of the function.
13+
error: `fn` that only maps over argument
1314
--> tests/ui/single_option_map.rs:7:1
1415
|
1516
LL | / fn j(arg: Option<u64>) -> Option<u64> {
1617
LL | | arg.map(|x| x * 2)
1718
LL | | }
1819
| |_^
20+
|
21+
= help: move the `.map` to the caller or to an `_opt` function
1922

2023
error: aborting due to 2 previous errors
2124

0 commit comments

Comments
 (0)