Skip to content

Commit 214b37b

Browse files
author
Yusuf Raji
committed
Add new test case
1 parent 40edb89 commit 214b37b

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

clippy_lints/src/single_option_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ declare_clippy_lint! {
1616
///
1717
/// ### Why is this bad?
1818
/// Taking and returning an `Option<T>` may require additional
19-
/// `Some(_)` and `unwrap` if all you have is a `T`
19+
/// `Some(_)` and `unwrap` if all you have is a `T`.
2020
///
2121
/// ### Example
2222
/// ```no_run

tests/ui/single_option_map.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ fn j(arg: Option<u64>) -> Option<u64> {
1515
arg.map(|x| x * 2)
1616
}
1717

18+
fn mul_args(a: String, b: u64) -> String {
19+
a
20+
}
21+
22+
fn mul_args_opt(a: Option<String>, b: u64) -> Option<String> {
23+
//~^ ERROR: `fn` that only maps over argument
24+
a.map(|val| mul_args(val, b + 1))
25+
}
26+
1827
// No lint: no `Option` argument argument
1928
fn maps_static_option() -> Option<usize> {
2029
MAYBE_ATOMIC.map(|a| a.load(Ordering::Relaxed))

tests/ui/single_option_map.stderr

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,16 @@ LL | | }
2222
|
2323
= help: move the `.map` to the caller or to an `_opt` function
2424

25-
error: aborting due to 2 previous errors
25+
error: `fn` that only maps over argument
26+
--> tests/ui/single_option_map.rs:23:1
27+
|
28+
LL | / fn mul_args_opt(a: Option<String>, b: u64) -> Option<String> {
29+
LL | |
30+
LL | | a.map(|val| mul_args(val, b + 1))
31+
LL | | }
32+
| |_^
33+
|
34+
= help: move the `.map` to the caller or to an `_opt` function
35+
36+
error: aborting due to 3 previous errors
2637

0 commit comments

Comments
 (0)