diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2019-12-06 15:37:06 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-06 15:37:06 +0900 |
| commit | 6c0165fa78c19a879b14f95b92b83d368ba6797c (patch) | |
| tree | 67bf568fc6033e7c09c7800fccd566b676a1eae7 /src/librustc_error_codes/error_codes | |
| parent | 3b878aa9ae719ec4dec574cf2d1848ef9023ff38 (diff) | |
| parent | 911b7d6d4dc19da085883d19b7a772b5ca35ffc9 (diff) | |
| download | rust-6c0165fa78c19a879b14f95b92b83d368ba6797c.tar.gz rust-6c0165fa78c19a879b14f95b92b83d368ba6797c.zip | |
Rollup merge of #66979 - reese:E0631-long-error, r=GuillaumeGomez
Add long error for E0631 and update ui tests. This PR adds a long error for `E0631`, which covers errors where closure argument types are mismatched. It also updates UI tests where this error is applicable. Part of #61137
Diffstat (limited to 'src/librustc_error_codes/error_codes')
| -rw-r--r-- | src/librustc_error_codes/error_codes/E0631.md | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/librustc_error_codes/error_codes/E0631.md b/src/librustc_error_codes/error_codes/E0631.md new file mode 100644 index 00000000000..6188d5f61a7 --- /dev/null +++ b/src/librustc_error_codes/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| {}); +} +``` |
