diff options
| author | Reese Williams <rtwill722@gmail.com> | 2019-12-03 07:51:11 -0500 |
|---|---|---|
| committer | Reese Williams <rtwill722@gmail.com> | 2019-12-03 07:51:11 -0500 |
| commit | 26a1ba85b890cdf7bbb7066c3a18aab84aef171f (patch) | |
| tree | 7f7dea58da934342d11adfd986d0cbe686bdaa3c /src/librustc_error_codes/error_codes | |
| parent | 7693bb9e1d122bea1b0645dcc201c6ed79c910e2 (diff) | |
| download | rust-26a1ba85b890cdf7bbb7066c3a18aab84aef171f.tar.gz rust-26a1ba85b890cdf7bbb7066c3a18aab84aef171f.zip | |
Use simpler code example for E0631 long error.
Diffstat (limited to 'src/librustc_error_codes/error_codes')
| -rw-r--r-- | src/librustc_error_codes/error_codes/E0631.md | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/librustc_error_codes/error_codes/E0631.md b/src/librustc_error_codes/error_codes/E0631.md index ad419f82250..6188d5f61a7 100644 --- a/src/librustc_error_codes/error_codes/E0631.md +++ b/src/librustc_error_codes/error_codes/E0631.md @@ -3,27 +3,25 @@ This error indicates a type mismatch in closure arguments. Erroneous code example: ```compile_fail,E0631 -fn test_strings(string_vec: Vec<String>) -> Vec<bool> { - string_vec - .iter() - .map(|arg: &i32| arg.eq("Test String")) - .collect() +fn foo<F: Fn(i32)>(f: F) { +} + +fn main() { + foo(|x: &str| {}); } ``` -The closure passed to `map` expects a `&String` argument, since `some_vec` -has the type `Vec<String>`. -However, the closure argument is annotated as an `&i32`, which does not match -the type of the iterable. +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 test_strings(string_vec: Vec<String>) -> Vec<bool> { - string_vec - .iter() - .map(|arg| arg.eq("Test String")) - .collect() +fn foo<F: Fn(i32)>(f: F) { +} + +fn main() { + foo(|x: i32| {}); } ``` |
