Skip to content

Commit 881bfb6

Browse files
authored
Rollup merge of #164190 - estebank:fn-signatures, r=chenyukang
Tweak wording of "expected/found signature" errors Do not incorrectly state that we expected a closure when we expected *anything* that conforms to an `Fn*` trait.
2 parents 58c344e + dc2da07 commit 881bfb6

79 files changed

Lines changed: 218 additions & 215 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎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
@@ -3624,9 +3624,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
36243624
// Print type mismatch
36253625
let (expected_args, given_args) = self.cmp(expected_ty, given_ty);
36263626
err.note_expected_found(
3627-
"a closure with signature",
3627+
"type with signature",
36283628
expected_args,
3629-
"a closure with signature",
3629+
&format!(
3630+
"{} with signature",
3631+
trait_pred.self_ty().skip_binder().prefix_string(self.tcx)
3632+
),
36303633
given_args,
36313634
);
36323635
}

‎library/core/src/ops/function.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ use crate::ptr::NonNull;
6767
// SAFETY: tidy is not smart enough to tell that the below unsafe block is a string
6868
label = "call the function in a closure: `|| unsafe {{ /* code */ }}`"
6969
),
70-
message = "expected an `{This:resolved}` closure, found `{Self}`",
71-
label = "expected an `{This:resolved}` closure, found `{Self}`"
70+
message = "expected `{This:resolved}` signature, found `{Self}`",
71+
label = "expected `{This:resolved}` signature, found `{Self}`"
7272
)]
7373
#[fundamental] // so that regex can rely that `&str: !FnMut`
7474
#[must_use = "closures are lazy and do nothing unless called"]
@@ -154,8 +154,8 @@ pub const trait Fn<Args: Tuple>: [const] FnMut<Args> {
154154
// SAFETY: tidy is not smart enough to tell that the below unsafe block is a string
155155
label = "call the function in a closure: `|| unsafe {{ /* code */ }}`"
156156
),
157-
message = "expected an `{This:resolved}` closure, found `{Self}`",
158-
label = "expected an `{This:resolved}` closure, found `{Self}`"
157+
message = "expected `{This:resolved}` signature, found `{Self}`",
158+
label = "expected `{This:resolved}` signature, found `{Self}`"
159159
)]
160160
#[fundamental] // so that regex can rely that `&str: !FnMut`
161161
#[must_use = "closures are lazy and do nothing unless called"]
@@ -233,8 +233,8 @@ pub const trait FnMut<Args: Tuple>: FnOnce<Args> {
233233
// SAFETY: tidy is not smart enough to tell that the below unsafe block is a string
234234
label = "call the function in a closure: `|| unsafe {{ /* code */ }}`"
235235
),
236-
message = "expected an `{This:resolved}` closure, found `{Self}`",
237-
label = "expected an `{This:resolved}` closure, found `{Self}`"
236+
message = "expected `{This:resolved}` signature, found `{Self}`",
237+
label = "expected `{This:resolved}` signature, found `{Self}`"
238238
)]
239239
#[fundamental] // so that regex can rely that `&str: !FnMut`
240240
#[must_use = "closures are lazy and do nothing unless called"]

‎tests/ui/abi/bad-custom.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ async unsafe extern "custom" fn no_async_fn() {
142142
}
143143

144144
fn no_promotion_to_fn_trait(f: unsafe extern "custom" fn()) -> impl Fn() {
145-
//~^ ERROR expected an `Fn()` closure, found `unsafe extern "custom" fn()`
145+
//~^ ERROR expected `Fn()` signature, found `unsafe extern "custom" fn()`
146146
f
147147
}
148148

‎tests/ui/abi/bad-custom.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ LL | unsafe extern "custom" fn no_cold_attribute() {
418418
| |
419419
| `extern "custom"` because of this
420420

421-
error[E0277]: expected an `Fn()` closure, found `unsafe extern "custom" fn()`
421+
error[E0277]: expected `Fn()` signature, found `unsafe extern "custom" fn()`
422422
--> $DIR/bad-custom.rs:144:64
423423
|
424424
LL | fn no_promotion_to_fn_trait(f: unsafe extern "custom" fn()) -> impl Fn() {

‎tests/ui/associated-types/normalization-ice-issue-149746.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ trait Owner { type Ty<T: FnMut()>; }
44
impl Owner for () { type Ty<T: FnMut()> = T; }
55
pub struct Warns<T> {
66
_significant_drop: <() as Owner>::Ty<T>,
7-
//~^ ERROR expected an `FnMut()` closure, found `T`
7+
//~^ ERROR expected `FnMut()` signature, found `T`
88
field: String,
99
}
1010
pub fn test<T>(w: Warns<T>) {
11-
//~^ ERROR expected an `FnMut()` closure, found `T`
11+
//~^ ERROR expected `FnMut()` signature, found `T`
1212
_ = || w.field
13-
//~^ ERROR expected an `FnMut()` closure, found `T`
14-
//~| ERROR expected an `FnMut()` closure, found `T`
13+
//~^ ERROR expected `FnMut()` signature, found `T`
14+
//~| ERROR expected `FnMut()` signature, found `T`
1515
//~| WARN: changes to closure capture in Rust 2021 will affect drop order
1616
}
1717
fn main() {}

‎tests/ui/associated-types/normalization-ice-issue-149746.stderr‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0277]: expected an `FnMut()` closure, found `T`
1+
error[E0277]: expected `FnMut()` signature, found `T`
22
--> $DIR/normalization-ice-issue-149746.rs:6:24
33
|
44
LL | _significant_drop: <() as Owner>::Ty<T>,
5-
| ^^^^^^^^^^^^^^^^^^^^ expected an `FnMut()` closure, found `T`
5+
| ^^^^^^^^^^^^^^^^^^^^ expected `FnMut()` signature, found `T`
66
|
77
= note: wrap the `T` in a closure with no arguments: `|| { /* code */ }`
88
note: required by a bound in `Owner::Ty`
@@ -35,11 +35,11 @@ help: add a dummy let to cause `w` to be fully captured
3535
LL | _ = || { let _ = &w; w.field }
3636
| +++++++++++++ +
3737

38-
error[E0277]: expected an `FnMut()` closure, found `T`
38+
error[E0277]: expected `FnMut()` signature, found `T`
3939
--> $DIR/normalization-ice-issue-149746.rs:12:9
4040
|
4141
LL | _ = || w.field
42-
| ^^^^^^^^^^ expected an `FnMut()` closure, found `T`
42+
| ^^^^^^^^^^ expected `FnMut()` signature, found `T`
4343
|
4444
= note: wrap the `T` in a closure with no arguments: `|| { /* code */ }`
4545
note: required by a bound in `Owner::Ty`
@@ -48,11 +48,11 @@ note: required by a bound in `Owner::Ty`
4848
LL | trait Owner { type Ty<T: FnMut()>; }
4949
| ^^^^^^^ required by this bound in `Owner::Ty`
5050

51-
error[E0277]: expected an `FnMut()` closure, found `T`
51+
error[E0277]: expected `FnMut()` signature, found `T`
5252
--> $DIR/normalization-ice-issue-149746.rs:10:16
5353
|
5454
LL | pub fn test<T>(w: Warns<T>) {
55-
| ^ expected an `FnMut()` closure, found `T`
55+
| ^ expected `FnMut()` signature, found `T`
5656
|
5757
= note: wrap the `T` in a closure with no arguments: `|| { /* code */ }`
5858
note: required by a bound in `Owner::Ty`
@@ -61,11 +61,11 @@ note: required by a bound in `Owner::Ty`
6161
LL | trait Owner { type Ty<T: FnMut()>; }
6262
| ^^^^^^^ required by this bound in `Owner::Ty`
6363

64-
error[E0277]: expected an `FnMut()` closure, found `T`
64+
error[E0277]: expected `FnMut()` signature, found `T`
6565
--> $DIR/normalization-ice-issue-149746.rs:12:9
6666
|
6767
LL | _ = || w.field
68-
| ^^^^^^^^^^ expected an `FnMut()` closure, found `T`
68+
| ^^^^^^^^^^ expected `FnMut()` signature, found `T`
6969
|
7070
= note: wrap the `T` in a closure with no arguments: `|| { /* code */ }`
7171
note: required by a bound in `Owner::Ty`

‎tests/ui/async-await/async-fn/impl-header.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ impl async Fn<()> for F {}
66
//~^ ERROR `async` trait implementations are unsupported
77
//~| ERROR the precise format of `Fn`-family traits' type parameters is subject to change
88
//~| ERROR manual implementations of `Fn` are experimental
9-
//~| ERROR expected an `FnMut()` closure, found `F`
9+
//~| ERROR expected `FnMut()` signature, found `F`
1010
//~| ERROR not all trait items implemented, missing: `call`
1111

1212
fn main() {}

‎tests/ui/async-await/async-fn/impl-header.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ LL | impl async Fn<()> for F {}
3030
|
3131
= help: implement the missing item: `fn call(&self, _: ()) -> <Self as FnOnce<()>>::Output { todo!() }` (unstable, requires feature `fn_traits`)
3232

33-
error[E0277]: expected an `FnMut()` closure, found `F`
33+
error[E0277]: expected `FnMut()` signature, found `F`
3434
--> $DIR/impl-header.rs:5:23
3535
|
3636
LL | impl async Fn<()> for F {}
37-
| ^ expected an `FnMut()` closure, found `F`
37+
| ^ expected `FnMut()` signature, found `F`
3838
|
3939
help: the trait `FnMut()` is not implemented for `F`
4040
--> $DIR/impl-header.rs:3:1

‎tests/ui/cast/raw-ptr-to-dyn-fn-raw-ptr.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ fn main() {
44
let ptr: *mut () = core::ptr::null_mut();
55
let _: &mut dyn Fn() = unsafe {
66
&mut *(ptr as *mut dyn Fn())
7-
//~^ ERROR expected an `Fn()` closure, found `()`
7+
//~^ ERROR expected `Fn()` signature, found `()`
88
};
99
}

‎tests/ui/cast/raw-ptr-to-dyn-fn-raw-ptr.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0277]: expected an `Fn()` closure, found `()`
1+
error[E0277]: expected `Fn()` signature, found `()`
22
--> $DIR/raw-ptr-to-dyn-fn-raw-ptr.rs:6:16
33
|
44
LL | &mut *(ptr as *mut dyn Fn())
5-
| ^^^ expected an `Fn()` closure, found `()`
5+
| ^^^ expected `Fn()` signature, found `()`
66
|
77
= help: the trait `Fn()` is not implemented for `()`
88
= note: wrap the `()` in a closure with no arguments: `|| { /* code */ }`

0 commit comments

Comments
 (0)