File tree 1 file changed +12
-14
lines changed
src/librustc_error_codes/error_codes
1 file changed +12
-14
lines changed Original file line number Diff line number Diff line change @@ -3,27 +3,25 @@ This error indicates a type mismatch in closure arguments.
3
3
Erroneous code example:
4
4
5
5
``` 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| {});
11
11
}
12
12
```
13
13
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.
18
16
19
17
This can be resolved by changing the type annotation or removing it entirely
20
18
if it can be inferred.
21
19
22
20
```
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| {});
28
26
}
29
27
```
You can’t perform that action at this time.
0 commit comments