]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_error_codes/src/error_codes/E0631.md
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / compiler / rustc_error_codes / src / error_codes / E0631.md
1 This error indicates a type mismatch in closure arguments.
2
3 Erroneous code example:
4
5 ```compile_fail,E0631
6 fn foo<F: Fn(i32)>(f: F) {
7 }
8
9 fn main() {
10 foo(|x: &str| {});
11 }
12 ```
13
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.
16
17 This can be resolved by changing the type annotation or removing it entirely
18 if it can be inferred.
19
20 ```
21 fn foo<F: Fn(i32)>(f: F) {
22 }
23
24 fn main() {
25 foo(|x: i32| {});
26 }
27 ```