Skip to content

Commit 9dd829f

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#61137
2 parents 4ddccd7 + 26a1ba8 commit 9dd829f

14 files changed

+47
-8
lines changed

src/librustc_error_codes/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ E0622: include_str!("./error_codes/E0622.md"),
347347
E0623: include_str!("./error_codes/E0623.md"),
348348
E0624: include_str!("./error_codes/E0624.md"),
349349
E0626: include_str!("./error_codes/E0626.md"),
350+
E0631: include_str!("./error_codes/E0631.md"),
350351
E0633: include_str!("./error_codes/E0633.md"),
351352
E0635: include_str!("./error_codes/E0635.md"),
352353
E0636: include_str!("./error_codes/E0636.md"),
@@ -580,7 +581,6 @@ E0745: include_str!("./error_codes/E0745.md"),
580581
// rustc_const_unstable attribute must be paired with stable/unstable
581582
// attribute
582583
E0630,
583-
E0631, // type mismatch in closure arguments
584584
E0632, // cannot provide explicit generic arguments when `impl Trait` is
585585
// used in argument position
586586
E0634, // type has conflicting packed representaton hints
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
```

src/test/ui/anonymous-higher-ranked-lifetime.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,4 @@ LL | fn h2<F>(_: F) where F: for<'t0> Fn(&(), Box<dyn Fn(&())>, &'t0 (), fn(&(),
121121

122122
error: aborting due to 11 previous errors
123123

124+
For more information about this error, try `rustc --explain E0631`.

src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,5 @@ LL | with_closure_expecting_fn_with_bound_region(|x: Foo<'_>, y| {
7777

7878
error: aborting due to 5 previous errors
7979

80-
For more information about this error, try `rustc --explain E0308`.
80+
Some errors have detailed explanations: E0308, E0631.
81+
For more information about an error, try `rustc --explain E0308`.

src/test/ui/closure-expected-type/expect-infer-var-appearing-twice.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ LL | with_closure(|x: u32, y: i32| {
1313

1414
error: aborting due to previous error
1515

16+
For more information about this error, try `rustc --explain E0631`.

src/test/ui/closures/issue-41366.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ LL | (&|_|()) as &dyn for<'x> Fn(<u32 as T<'x>>::V);
1919

2020
error: aborting due to 2 previous errors
2121

22-
For more information about this error, try `rustc --explain E0271`.
22+
Some errors have detailed explanations: E0271, E0631.
23+
For more information about an error, try `rustc --explain E0271`.

src/test/ui/issues/issue-43623.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ LL | break_me::<Type, fn(_)>;
2525

2626
error: aborting due to 2 previous errors
2727

28-
For more information about this error, try `rustc --explain E0271`.
28+
Some errors have detailed explanations: E0271, E0631.
29+
For more information about an error, try `rustc --explain E0271`.

src/test/ui/issues/issue-60283.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ LL | foo((), drop)
2727

2828
error: aborting due to 2 previous errors
2929

30-
For more information about this error, try `rustc --explain E0271`.
30+
Some errors have detailed explanations: E0271, E0631.
31+
For more information about an error, try `rustc --explain E0271`.

src/test/ui/mismatched_types/E0631.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ LL | bar(f);
4646

4747
error: aborting due to 4 previous errors
4848

49+
For more information about this error, try `rustc --explain E0631`.

src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ LL | baz(f);
4545

4646
error: aborting due to 5 previous errors
4747

48-
For more information about this error, try `rustc --explain E0271`.
48+
Some errors have detailed explanations: E0271, E0631.
49+
For more information about an error, try `rustc --explain E0271`.

src/test/ui/mismatched_types/closure-mismatch.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ LL | baz(|_| ());
2424

2525
error: aborting due to 2 previous errors
2626

27-
For more information about this error, try `rustc --explain E0271`.
27+
Some errors have detailed explanations: E0271, E0631.
28+
For more information about an error, try `rustc --explain E0271`.

src/test/ui/mismatched_types/fn-variance-1.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ LL | apply(&mut 3, takes_imm);
2424

2525
error: aborting due to 2 previous errors
2626

27+
For more information about this error, try `rustc --explain E0631`.

src/test/ui/mismatched_types/issue-36053-2.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ LL | once::<&str>("str").fuse().filter(|a: &str| true).count();
1818

1919
error: aborting due to 2 previous errors
2020

21-
For more information about this error, try `rustc --explain E0599`.
21+
Some errors have detailed explanations: E0599, E0631.
22+
For more information about an error, try `rustc --explain E0599`.

src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ LL | let z = call_it(3, f);
1212

1313
error: aborting due to previous error
1414

15+
For more information about this error, try `rustc --explain E0631`.

0 commit comments

Comments
 (0)