Skip to content

Commit 3c77188

Browse files
committed
Auto merge of rust-lang#5460 - phansch:fix_incorrect_tests, r=matthiaskrgr
result_map_unit_fn: Fix incorrect UI tests `x` and the `HasResult` struct were missing in this file. changelog: none
2 parents d236b30 + 9a52d52 commit 3c77188

File tree

2 files changed

+52
-15
lines changed

2 files changed

+52
-15
lines changed

tests/ui/result_map_unit_fn_unfixable.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#![feature(never_type)]
33
#![allow(unused)]
44

5+
struct HasResult {
6+
field: Result<usize, usize>,
7+
}
8+
59
fn do_nothing<T>(_: T) {}
610

711
fn diverge<T>(_: T) -> ! {
@@ -14,6 +18,8 @@ fn plus_one(value: usize) -> usize {
1418

1519
#[rustfmt::skip]
1620
fn result_map_unit_fn() {
21+
let x = HasResult { field: Ok(10) };
22+
1723
x.field.map(|value| { do_nothing(value); do_nothing(value) });
1824

1925
x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) });

tests/ui/result_map_unit_fn_unfixable.stderr

+46-15
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,58 @@
1-
error[E0425]: cannot find value `x` in this scope
2-
--> $DIR/result_map_unit_fn_unfixable.rs:17:5
1+
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type
2+
--> $DIR/result_map_unit_fn_unfixable.rs:23:5
33
|
44
LL | x.field.map(|value| { do_nothing(value); do_nothing(value) });
5-
| ^ not found in this scope
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
6+
| |
7+
| help: try this: `if let Ok(value) = x.field { ... }`
8+
|
9+
= note: `-D clippy::result-map-unit-fn` implied by `-D warnings`
610

7-
error[E0425]: cannot find value `x` in this scope
8-
--> $DIR/result_map_unit_fn_unfixable.rs:19:5
11+
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type
12+
--> $DIR/result_map_unit_fn_unfixable.rs:25:5
913
|
1014
LL | x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) });
11-
| ^ not found in this scope
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
16+
| |
17+
| help: try this: `if let Ok(value) = x.field { ... }`
1218

13-
error[E0425]: cannot find value `x` in this scope
14-
--> $DIR/result_map_unit_fn_unfixable.rs:23:5
19+
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type
20+
--> $DIR/result_map_unit_fn_unfixable.rs:29:5
1521
|
16-
LL | x.field.map(|value| {
17-
| ^ not found in this scope
22+
LL | x.field.map(|value| {
23+
| _____^
24+
| |_____|
25+
| ||
26+
LL | || do_nothing(value);
27+
LL | || do_nothing(value)
28+
LL | || });
29+
| ||______^- help: try this: `if let Ok(value) = x.field { ... }`
30+
| |_______|
31+
|
1832

19-
error[E0425]: cannot find value `x` in this scope
20-
--> $DIR/result_map_unit_fn_unfixable.rs:27:5
33+
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type
34+
--> $DIR/result_map_unit_fn_unfixable.rs:33:5
2135
|
2236
LL | x.field.map(|value| { do_nothing(value); do_nothing(value); });
23-
| ^ not found in this scope
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
38+
| |
39+
| help: try this: `if let Ok(value) = x.field { ... }`
40+
41+
error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type
42+
--> $DIR/result_map_unit_fn_unfixable.rs:37:5
43+
|
44+
LL | "12".parse::<i32>().map(diverge);
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
46+
| |
47+
| help: try this: `if let Ok(a) = "12".parse::<i32>() { diverge(a) }`
48+
49+
error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type
50+
--> $DIR/result_map_unit_fn_unfixable.rs:43:5
51+
|
52+
LL | y.map(do_nothing);
53+
| ^^^^^^^^^^^^^^^^^-
54+
| |
55+
| help: try this: `if let Ok(_y) = y { do_nothing(_y) }`
2456

25-
error: aborting due to 4 previous errors
57+
error: aborting due to 6 previous errors
2658

27-
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)