Skip to content

Commit 993f5b3

Browse files
Yusuf Rajisamueltardieu
andcommitted
Add more test cases
Co-authored-by: Samuel Tardieu <[email protected]>
1 parent 3835332 commit 993f5b3

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

tests/ui/single_option_map.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ fn manipulate_opt(opt_i: Option<i32>) -> Option<i32> {
2929
opt_i.map(manipulate)
3030
}
3131

32+
// No lint: maps other than the receiver
33+
fn map_not_arg(arg: Option<u32>) -> Option<u32> {
34+
maps_static_option().map(|_| arg.unwrap())
35+
}
36+
37+
// No lint: wrapper function with η-expanded form
38+
#[allow(clippy::redundant_closure)]
39+
fn manipulate_opt_explicit(opt_i: Option<i32>) -> Option<i32> {
40+
opt_i.map(|x| manipulate(x))
41+
}
42+
3243
fn main() {
3344
let answer = Some(42u32);
3445
let h_result = h(answer);

tests/ui/single_option_map.stderr

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ error: `fn` that only maps over argument
22
--> tests/ui/single_option_map.rs:8:1
33
|
44
LL | / fn h(arg: Option<u32>) -> Option<u32> {
5+
LL | |
56
LL | | arg.map(|x| x * 2)
67
LL | | }
78
| |_^
@@ -11,14 +12,25 @@ LL | | }
1112
= help: to override `-D warnings` add `#[allow(clippy::single_option_map)]`
1213

1314
error: `fn` that only maps over argument
14-
--> tests/ui/single_option_map.rs:12:1
15+
--> tests/ui/single_option_map.rs:13:1
1516
|
1617
LL | / fn j(arg: Option<u64>) -> Option<u64> {
18+
LL | |
1719
LL | | arg.map(|x| x * 2)
1820
LL | | }
1921
| |_^
2022
|
2123
= help: move the `.map` to the caller or to an `_opt` function
2224

23-
error: aborting due to 2 previous errors
25+
error: `fn` that only maps over argument
26+
--> tests/ui/single_option_map.rs:39:1
27+
|
28+
LL | / fn manipulate_opt_explicit(opt_i: Option<i32>) -> Option<i32> {
29+
LL | | opt_i.map(|x| manipulate(x))
30+
LL | | }
31+
| |_^
32+
|
33+
= help: move the `.map` to the caller or to an `_opt` function
34+
35+
error: aborting due to 3 previous errors
2436

0 commit comments

Comments
 (0)