Skip to content

Commit

Permalink
Fix single_option_map lint emission
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusuf Raji committed Jan 21, 2025
1 parent 009f955 commit 609541b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 5 additions & 3 deletions clippy_lints/src/single_option_map.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clippy_utils::diagnostics::span_lint;
use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::peel_blocks;
use clippy_utils::ty::is_type_diagnostic_item;
use rustc_hir::def_id::LocalDefId;
Expand Down Expand Up @@ -57,11 +57,13 @@ impl<'tcx> LateLintPass<'tcx> for SingleOptionMap {
&& is_type_diagnostic_item(cx, callee_type, sym::Option)
&& let ExprKind::Path(_path) = callee.kind
{
span_lint(
span_lint_and_help(
cx,
SINGLE_OPTION_MAP,
span,
"mapping over single function argument of `Option<T>`, to return `Option<T>`, can be best expressed by applying the map outside of the function.",
"`fn` that only maps over argument",
None,
"move the `.map` to the caller or to an `_opt` function",
);
}
}
Expand Down
7 changes: 5 additions & 2 deletions tests/ui/single_option_map.stderr
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
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.
error: `fn` that only maps over argument
--> tests/ui/single_option_map.rs:3:1
|
LL | / fn h(arg: Option<u32>) -> Option<u32> {
LL | | arg.map(|x| x * 2)
LL | | }
| |_^
|
= help: move the `.map` to the caller or to an `_opt` function
= note: `-D clippy::single-option-map` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::single_option_map)]`

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.
error: `fn` that only maps over argument
--> tests/ui/single_option_map.rs:7:1
|
LL | / fn j(arg: Option<u64>) -> Option<u64> {
LL | | arg.map(|x| x * 2)
LL | | }
| |_^
|
= help: move the `.map` to the caller or to an `_opt` function

error: aborting due to 2 previous errors

0 comments on commit 609541b

Please sign in to comment.