diff options
Diffstat (limited to 'compiler/rustc_error_codes/src/error_codes/E0631.md')
-rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0631.md | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0631.md b/compiler/rustc_error_codes/src/error_codes/E0631.md new file mode 100644 index 000000000..6188d5f61 --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0631.md @@ -0,0 +1,27 @@ +This error indicates a type mismatch in closure arguments. + +Erroneous code example: + +```compile_fail,E0631 +fn foo<F: Fn(i32)>(f: F) { +} + +fn main() { + foo(|x: &str| {}); +} +``` + +The error occurs because `foo` accepts a closure that takes an `i32` argument, +but in `main`, it is passed a closure with a `&str` argument. + +This can be resolved by changing the type annotation or removing it entirely +if it can be inferred. + +``` +fn foo<F: Fn(i32)>(f: F) { +} + +fn main() { + foo(|x: i32| {}); +} +``` |