File tree Expand file tree Collapse file tree 1 file changed +12
-14
lines changed
src/librustc_error_codes/error_codes Expand file tree Collapse file tree 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.
33Erroneous 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
1917This can be resolved by changing the type annotation or removing it entirely
2018if 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```
You can’t perform that action at this time.
0 commit comments