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
This commit is contained in:
Yuki Okushi 2019-12-06 15:37:06 +09:00 committed by GitHub
commit 6c0165fa78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 48 additions and 8 deletions

View file

@ -347,6 +347,7 @@ E0622: include_str!("./error_codes/E0622.md"),
E0623: include_str!("./error_codes/E0623.md"),
E0624: include_str!("./error_codes/E0624.md"),
E0626: include_str!("./error_codes/E0626.md"),
E0631: include_str!("./error_codes/E0631.md"),
E0633: include_str!("./error_codes/E0633.md"),
E0635: include_str!("./error_codes/E0635.md"),
E0636: include_str!("./error_codes/E0636.md"),
@ -580,7 +581,6 @@ E0745: include_str!("./error_codes/E0745.md"),
// rustc_const_unstable attribute must be paired with stable/unstable
// attribute
E0630,
E0631, // type mismatch in closure arguments
E0632, // cannot provide explicit generic arguments when `impl Trait` is
// used in argument position
E0634, // type has conflicting packed representaton hints

View file

@ -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| {});
}
```