Skip to content

Commit dc2da07

Browse files
committed
Be more accurate on expected and found signatures
``` error[E0277]: expected `Fn(<_ as ATC<'a>>::Type)` signature, found `F` --> $DIR/issue-62529-3.rs:25:14 | LL | call(f, ()); | ---- ^ expected `Fn(<_ as ATC<'a>>::Type)` signature, found `F` | | | required by a bound introduced by this call | = note: expected type with signature `for<'a> fn(<_ as ATC<'a>>::Type)` found type parameter with signature `fn(())` note: required by a bound in `call` --> $DIR/issue-62529-3.rs:9:36 | LL | fn call<'b, T: for<'a> ATC<'a>, F: for<'a> Fn(<T as ATC<'a>>::Type)>( | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `call` ```
1 parent f3ace40 commit dc2da07

10 files changed

Lines changed: 43 additions & 40 deletions

File tree

‎compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3632,9 +3632,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
36323632
// Print type mismatch
36333633
let (expected_args, given_args) = self.cmp(expected_ty, given_ty);
36343634
err.note_expected_found(
3635-
"a closure with signature",
3635+
"type with signature",
36363636
expected_args,
3637-
"a closure with signature",
3637+
&format!(
3638+
"{} with signature",
3639+
trait_pred.self_ty().skip_binder().prefix_string(self.tcx)
3640+
),
36383641
given_args,
36393642
);
36403643
}

‎tests/ui/higher-ranked/trait-bounds/normalize-under-binder/issue-62529-3.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | call(f, ());
66
| |
77
| required by a bound introduced by this call
88
|
9-
= note: expected a closure with signature `for<'a> fn(<_ as ATC<'a>>::Type)`
10-
found a closure with signature `fn(())`
9+
= note: expected type with signature `for<'a> fn(<_ as ATC<'a>>::Type)`
10+
found type parameter with signature `fn(())`
1111
note: required by a bound in `call`
1212
--> $DIR/issue-62529-3.rs:9:36
1313
|

‎tests/ui/implied-bounds/issue-100690.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | real_dispatch(f)
66
| |
77
| required by a bound introduced by this call
88
|
9-
= note: expected a closure with signature `for<'a, 'b> fn(&'a mut UIView<'b, _>)`
10-
found a closure with signature `fn(&mut UIView<'a, _>)`
9+
= note: expected type with signature `for<'a, 'b> fn(&'a mut UIView<'b, _>)`
10+
found type parameter with signature `fn(&mut UIView<'a, _>)`
1111
note: required by a bound in `real_dispatch`
1212
--> $DIR/issue-100690.rs:8:8
1313
|

‎tests/ui/mismatched_types/closure-arg-type-mismatch-issue-45727.next.stderr‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ help: the trait `for<'a> FnMut(&'a {integer})` is not implemented for closure `{
1111
|
1212
LL | let _ = (-10..=10).find(|x: i32| x.signum() == 0);
1313
| ^^^^^^^^
14-
= note: expected a closure with signature `for<'a> fn(&'a {integer})`
15-
found a closure with signature `fn(i32)`
14+
= note: expected type with signature `for<'a> fn(&'a {integer})`
15+
found closure with signature `fn(i32)`
1616
note: required by a bound in `find`
1717
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
1818

@@ -29,8 +29,8 @@ help: the trait `for<'a> FnMut(&'a {integer})` is not implemented for closure `{
2929
|
3030
LL | let _ = (-10..=10).find(|x: &&&i32| x.signum() == 0);
3131
| ^^^^^^^^^^^
32-
= note: expected a closure with signature `for<'a> fn(&'a {integer})`
33-
found a closure with signature `fn(&&&i32)`
32+
= note: expected type with signature `for<'a> fn(&'a {integer})`
33+
found closure with signature `fn(&&&i32)`
3434
note: required by a bound in `find`
3535
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
3636

‎tests/ui/mismatched_types/closure-mismatch.next.stderr‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ help: the trait `for<'a> FnOnce(&'a ())` is not implemented for closure `{closur
1111
|
1212
LL | baz(|_| ());
1313
| ^^^
14-
= note: expected a closure with signature `for<'a> fn(&'a ())`
15-
found a closure with signature `fn(&())`
14+
= note: expected type with signature `for<'a> fn(&'a ())`
15+
found closure with signature `fn(&())`
1616
note: required for `{closure@$DIR/closure-mismatch.rs:12:9: 12:12}` to implement `Foo`
1717
--> $DIR/closure-mismatch.rs:7:18
1818
|
@@ -39,8 +39,8 @@ help: the trait `for<'a> FnOnce(&'a ())` is not implemented for closure `{closur
3939
|
4040
LL | baz(|x| ());
4141
| ^^^
42-
= note: expected a closure with signature `for<'a> fn(&'a ())`
43-
found a closure with signature `fn(&())`
42+
= note: expected type with signature `for<'a> fn(&'a ())`
43+
found closure with signature `fn(&())`
4444
note: required for `{closure@$DIR/closure-mismatch.rs:16:9: 16:12}` to implement `Foo`
4545
--> $DIR/closure-mismatch.rs:7:18
4646
|

‎tests/ui/rfcs/rfc-2396-target_feature-11/fn-traits.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ fn call_once_i32(f: impl FnOnce(i32)) {
2626
}
2727

2828
fn main() {
29-
call(foo); //~ ERROR expected an `Fn()` closure, found `#[target_feature(..)] fn() {foo}`
30-
call_mut(foo); //~ ERROR expected an `FnMut()` closure, found `#[target_feature(..)] fn() {foo}`
31-
call_once(foo); //~ ERROR expected an `FnOnce()` closure, found `#[target_feature(..)] fn() {foo}`
32-
call_once_i32(bar); //~ ERROR expected an `FnOnce(i32)` closure, found `#[target_feature(..)] fn(i32) {bar}`
29+
call(foo); //~ ERROR expected `Fn()` signature, found `#[target_feature(..)] fn() {foo}`
30+
call_mut(foo); //~ ERROR expected `FnMut()` signature, found `#[target_feature(..)] fn() {foo}`
31+
call_once(foo); //~ ERROR expected `FnOnce()` signature, found `#[target_feature(..)] fn() {foo}`
32+
call_once_i32(bar); //~ ERROR expected `FnOnce(i32)` signature, found `#[target_feature(..)] fn(i32) {bar}`
3333

3434
call(foo_unsafe);
35-
//~^ ERROR expected an `Fn()` closure, found `unsafe fn() {foo_unsafe}`
35+
//~^ ERROR expected `Fn()` signature, found `unsafe fn() {foo_unsafe}`
3636
call_mut(foo_unsafe);
37-
//~^ ERROR expected an `FnMut()` closure, found `unsafe fn() {foo_unsafe}`
37+
//~^ ERROR expected `FnMut()` signature, found `unsafe fn() {foo_unsafe}`
3838
call_once(foo_unsafe);
39-
//~^ ERROR expected an `FnOnce()` closure, found `unsafe fn() {foo_unsafe}`
39+
//~^ ERROR expected `FnOnce()` signature, found `unsafe fn() {foo_unsafe}`
4040
}

‎tests/ui/rfcs/rfc-2396-target_feature-11/fn-traits.stderr‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0277]: expected an `Fn()` closure, found `#[target_feature(..)] fn() {foo}`
1+
error[E0277]: expected `Fn()` signature, found `#[target_feature(..)] fn() {foo}`
22
--> $DIR/fn-traits.rs:29:10
33
|
44
LL | call(foo);
5-
| ---- ^^^ expected an `Fn()` closure, found `#[target_feature(..)] fn() {foo}`
5+
| ---- ^^^ expected `Fn()` signature, found `#[target_feature(..)] fn() {foo}`
66
| |
77
| required by a bound introduced by this call
88
|
@@ -16,11 +16,11 @@ note: required by a bound in `call`
1616
LL | fn call(f: impl Fn()) {
1717
| ^^^^ required by this bound in `call`
1818

19-
error[E0277]: expected an `FnMut()` closure, found `#[target_feature(..)] fn() {foo}`
19+
error[E0277]: expected `FnMut()` signature, found `#[target_feature(..)] fn() {foo}`
2020
--> $DIR/fn-traits.rs:30:14
2121
|
2222
LL | call_mut(foo);
23-
| -------- ^^^ expected an `FnMut()` closure, found `#[target_feature(..)] fn() {foo}`
23+
| -------- ^^^ expected `FnMut()` signature, found `#[target_feature(..)] fn() {foo}`
2424
| |
2525
| required by a bound introduced by this call
2626
|
@@ -34,11 +34,11 @@ note: required by a bound in `call_mut`
3434
LL | fn call_mut(mut f: impl FnMut()) {
3535
| ^^^^^^^ required by this bound in `call_mut`
3636

37-
error[E0277]: expected an `FnOnce()` closure, found `#[target_feature(..)] fn() {foo}`
37+
error[E0277]: expected `FnOnce()` signature, found `#[target_feature(..)] fn() {foo}`
3838
--> $DIR/fn-traits.rs:31:15
3939
|
4040
LL | call_once(foo);
41-
| --------- ^^^ expected an `FnOnce()` closure, found `#[target_feature(..)] fn() {foo}`
41+
| --------- ^^^ expected `FnOnce()` signature, found `#[target_feature(..)] fn() {foo}`
4242
| |
4343
| required by a bound introduced by this call
4444
|
@@ -52,11 +52,11 @@ note: required by a bound in `call_once`
5252
LL | fn call_once(f: impl FnOnce()) {
5353
| ^^^^^^^^ required by this bound in `call_once`
5454

55-
error[E0277]: expected an `FnOnce(i32)` closure, found `#[target_feature(..)] fn(i32) {bar}`
55+
error[E0277]: expected `FnOnce(i32)` signature, found `#[target_feature(..)] fn(i32) {bar}`
5656
--> $DIR/fn-traits.rs:32:19
5757
|
5858
LL | call_once_i32(bar);
59-
| ------------- ^^^ expected an `FnOnce(i32)` closure, found `#[target_feature(..)] fn(i32) {bar}`
59+
| ------------- ^^^ expected `FnOnce(i32)` signature, found `#[target_feature(..)] fn(i32) {bar}`
6060
| |
6161
| required by a bound introduced by this call
6262
|
@@ -69,7 +69,7 @@ note: required by a bound in `call_once_i32`
6969
LL | fn call_once_i32(f: impl FnOnce(i32)) {
7070
| ^^^^^^^^^^^ required by this bound in `call_once_i32`
7171

72-
error[E0277]: expected an `Fn()` closure, found `unsafe fn() {foo_unsafe}`
72+
error[E0277]: expected `Fn()` signature, found `unsafe fn() {foo_unsafe}`
7373
--> $DIR/fn-traits.rs:34:10
7474
|
7575
LL | call(foo_unsafe);
@@ -88,7 +88,7 @@ note: required by a bound in `call`
8888
LL | fn call(f: impl Fn()) {
8989
| ^^^^ required by this bound in `call`
9090

91-
error[E0277]: expected an `FnMut()` closure, found `unsafe fn() {foo_unsafe}`
91+
error[E0277]: expected `FnMut()` signature, found `unsafe fn() {foo_unsafe}`
9292
--> $DIR/fn-traits.rs:36:14
9393
|
9494
LL | call_mut(foo_unsafe);
@@ -107,7 +107,7 @@ note: required by a bound in `call_mut`
107107
LL | fn call_mut(mut f: impl FnMut()) {
108108
| ^^^^^^^ required by this bound in `call_mut`
109109

110-
error[E0277]: expected an `FnOnce()` closure, found `unsafe fn() {foo_unsafe}`
110+
error[E0277]: expected `FnOnce()` signature, found `unsafe fn() {foo_unsafe}`
111111
--> $DIR/fn-traits.rs:38:15
112112
|
113113
LL | call_once(foo_unsafe);

‎tests/ui/trait-bounds/mismatch-fn-trait.stderr‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | take(f)
66
| |
77
| required by a bound introduced by this call
88
|
9-
= note: expected a closure with signature `fn(i32)`
10-
found a closure with signature `fn(u32)`
9+
= note: expected type with signature `fn(i32)`
10+
found type parameter with signature `fn(u32)`
1111
note: required by a bound in `take`
1212
--> $DIR/mismatch-fn-trait.rs:1:18
1313
|
@@ -68,8 +68,8 @@ LL | take(f)
6868
| required by a bound introduced by this call
6969
|
7070
= note: `impl FnOnce(u32)` implements `FnOnce`, but it must implement `FnMut`, which is more general
71-
= note: expected a closure with signature `fn(i32)`
72-
found a closure with signature `fn(u32)`
71+
= note: expected type with signature `fn(i32)`
72+
found type parameter with signature `fn(u32)`
7373
note: required by a bound in `take`
7474
--> $DIR/mismatch-fn-trait.rs:1:18
7575
|

‎tests/ui/typeck/issue-116864.current.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ LL | | where
88
LL | | BAZ: Baz<Param = i32>,
99
| |__________________________^ expected `FnMut(&'any i32)` signature, found `impl for<'any> FnMutFut<&'any BAZ::Param, ()>`
1010
|
11-
= note: expected a closure with signature `for<'any> fn(&'any i32)`
12-
found a closure with signature `fn(&<BAZ as Baz>::Param)`
11+
= note: expected type with signature `for<'any> fn(&'any i32)`
12+
found type parameter with signature `fn(&<BAZ as Baz>::Param)`
1313
note: required for `impl for<'any> FnMutFut<&'any BAZ::Param, ()>` to implement `for<'any> FnMutFut<&'any i32, ()>`
1414
--> $DIR/issue-116864.rs:21:20
1515
|

‎tests/ui/typeck/issue-116864.next.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ LL | | where
88
LL | | BAZ: Baz<Param = i32>,
99
| |__________________________^ expected `FnOnce(&'any i32)` signature, found `impl for<'any> FnMutFut<&'any BAZ::Param, ()>`
1010
|
11-
= note: expected a closure with signature `for<'any> fn(&'any i32)`
12-
found a closure with signature `fn(&<BAZ as Baz>::Param)`
11+
= note: expected type with signature `for<'any> fn(&'any i32)`
12+
found type parameter with signature `fn(&<BAZ as Baz>::Param)`
1313
note: required for `impl for<'any> FnMutFut<&'any BAZ::Param, ()>` to implement `for<'any> FnMutFut<&'any i32, ()>`
1414
--> $DIR/issue-116864.rs:21:20
1515
|

0 commit comments

Comments
 (0)