]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0631.md
docs: revert removal of `E0729`
[rust.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 ```