Skip to content

Commit 0d283cc

Browse files
committed
Auto merge of rust-lang#7996 - togami2864:test-map-or-none, r=Manishearth
Add test case for RESULT_MAP_OR_INTO_OPTION just added test case for RESULT_MAP_OR_INTO_OPTION. changelog: none
2 parents 2776076 + cd81bb9 commit 0d283cc

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

tests/ui/option_map_or_none.fixed

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
fn main() {
66
let opt = Some(1);
7+
let r: Result<i32, i32> = Ok(1);
78
let bar = |_| Some(1);
89

910
// Check `OPTION_MAP_OR_NONE`.
@@ -19,4 +20,7 @@ fn main() {
1920
let height = x;
2021
Some(offset + height)
2122
});
23+
24+
// Check `RESULT_MAP_OR_INTO_OPTION`.
25+
let _: Option<i32> = r.ok();
2226
}

tests/ui/option_map_or_none.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
fn main() {
66
let opt = Some(1);
7+
let r: Result<i32, i32> = Ok(1);
78
let bar = |_| Some(1);
89

910
// Check `OPTION_MAP_OR_NONE`.
@@ -21,4 +22,7 @@ fn main() {
2122
let height = x;
2223
Some(offset + height)
2324
});
25+
26+
// Check `RESULT_MAP_OR_INTO_OPTION`.
27+
let _: Option<i32> = r.map_or(None, Some);
2428
}

tests/ui/option_map_or_none.stderr

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead
2-
--> $DIR/option_map_or_none.rs:11:26
2+
--> $DIR/option_map_or_none.rs:12:26
33
|
44
LL | let _: Option<i32> = opt.map_or(None, |x| Some(x + 1));
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `map` instead: `opt.map(|x| x + 1)`
66
|
77
= note: `-D clippy::option-map-or-none` implied by `-D warnings`
88

99
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead
10-
--> $DIR/option_map_or_none.rs:14:26
10+
--> $DIR/option_map_or_none.rs:15:26
1111
|
1212
LL | let _: Option<i32> = opt.map_or(None, |x| {
1313
| __________________________^
@@ -16,13 +16,13 @@ LL | | });
1616
| |_________________________^ help: try using `map` instead: `opt.map(|x| x + 1)`
1717

1818
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead
19-
--> $DIR/option_map_or_none.rs:18:26
19+
--> $DIR/option_map_or_none.rs:19:26
2020
|
2121
LL | let _: Option<i32> = opt.map_or(None, bar);
2222
| ^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `opt.and_then(bar)`
2323

2424
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead
25-
--> $DIR/option_map_or_none.rs:19:26
25+
--> $DIR/option_map_or_none.rs:20:26
2626
|
2727
LL | let _: Option<i32> = opt.map_or(None, |x| {
2828
| __________________________^
@@ -41,5 +41,13 @@ LL + Some(offset + height)
4141
LL ~ });
4242
|
4343

44-
error: aborting due to 4 previous errors
44+
error: called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling `ok()` instead
45+
--> $DIR/option_map_or_none.rs:27:26
46+
|
47+
LL | let _: Option<i32> = r.map_or(None, Some);
48+
| ^^^^^^^^^^^^^^^^^^^^ help: try using `ok` instead: `r.ok()`
49+
|
50+
= note: `-D clippy::result-map-or-into-option` implied by `-D warnings`
51+
52+
error: aborting due to 5 previous errors
4553

0 commit comments

Comments
 (0)