Skip to content

Commit 26a1ba8

Browse files
committed
Use simpler code example for E0631 long error.
1 parent 7693bb9 commit 26a1ba8

File tree

1 file changed

+12
-14
lines changed
  • src/librustc_error_codes/error_codes

1 file changed

+12
-14
lines changed

src/librustc_error_codes/error_codes/E0631.md

+12-14
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,25 @@ This error indicates a type mismatch in closure arguments.
33
Erroneous code example:
44

55
```compile_fail,E0631
6-
fn test_strings(string_vec: Vec<String>) -> Vec<bool> {
7-
string_vec
8-
.iter()
9-
.map(|arg: &i32| arg.eq("Test String"))
10-
.collect()
6+
fn foo<F: Fn(i32)>(f: F) {
7+
}
8+
9+
fn main() {
10+
foo(|x: &str| {});
1111
}
1212
```
1313

14-
The closure passed to `map` expects a `&String` argument, since `some_vec`
15-
has the type `Vec<String>`.
16-
However, the closure argument is annotated as an `&i32`, which does not match
17-
the type of the iterable.
14+
The error occurs because `foo` accepts a closure that takes an `i32` argument,
15+
but in `main`, it is passed a closure with a `&str` argument.
1816

1917
This can be resolved by changing the type annotation or removing it entirely
2018
if it can be inferred.
2119

2220
```
23-
fn test_strings(string_vec: Vec<String>) -> Vec<bool> {
24-
string_vec
25-
.iter()
26-
.map(|arg| arg.eq("Test String"))
27-
.collect()
21+
fn foo<F: Fn(i32)>(f: F) {
22+
}
23+
24+
fn main() {
25+
foo(|x: i32| {});
2826
}
2927
```

0 commit comments

Comments
 (0)