Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3632,9 +3632,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// Print type mismatch
let (expected_args, given_args) = self.cmp(expected_ty, given_ty);
err.note_expected_found(
"a closure with signature",
"type with signature",
expected_args,
"a closure with signature",
&format!(
"{} with signature",
trait_pred.self_ty().skip_binder().prefix_string(self.tcx)
),
given_args,
);
}
Expand Down
12 changes: 6 additions & 6 deletions library/core/src/ops/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ use crate::ptr::NonNull;
// SAFETY: tidy is not smart enough to tell that the below unsafe block is a string
label = "call the function in a closure: `|| unsafe {{ /* code */ }}`"
),
message = "expected an `{This:resolved}` closure, found `{Self}`",
label = "expected an `{This:resolved}` closure, found `{Self}`"
message = "expected `{This:resolved}` signature, found `{Self}`",
label = "expected `{This:resolved}` signature, found `{Self}`"
)]
#[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use = "closures are lazy and do nothing unless called"]
Expand Down Expand Up @@ -154,8 +154,8 @@ pub const trait Fn<Args: Tuple>: [const] FnMut<Args> {
// SAFETY: tidy is not smart enough to tell that the below unsafe block is a string
label = "call the function in a closure: `|| unsafe {{ /* code */ }}`"
),
message = "expected an `{This:resolved}` closure, found `{Self}`",
label = "expected an `{This:resolved}` closure, found `{Self}`"
message = "expected `{This:resolved}` signature, found `{Self}`",
label = "expected `{This:resolved}` signature, found `{Self}`"
)]
#[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use = "closures are lazy and do nothing unless called"]
Expand Down Expand Up @@ -233,8 +233,8 @@ pub const trait FnMut<Args: Tuple>: FnOnce<Args> {
// SAFETY: tidy is not smart enough to tell that the below unsafe block is a string
label = "call the function in a closure: `|| unsafe {{ /* code */ }}`"
),
message = "expected an `{This:resolved}` closure, found `{Self}`",
label = "expected an `{This:resolved}` closure, found `{Self}`"
message = "expected `{This:resolved}` signature, found `{Self}`",
label = "expected `{This:resolved}` signature, found `{Self}`"
)]
#[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use = "closures are lazy and do nothing unless called"]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/abi/bad-custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ async unsafe extern "custom" fn no_async_fn() {
}

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

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/abi/bad-custom.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ LL | unsafe extern "custom" fn no_cold_attribute() {
| |
| `extern "custom"` because of this

error[E0277]: expected an `Fn()` closure, found `unsafe extern "custom" fn()`
error[E0277]: expected `Fn()` signature, found `unsafe extern "custom" fn()`
--> $DIR/bad-custom.rs:144:64
|
LL | fn no_promotion_to_fn_trait(f: unsafe extern "custom" fn()) -> impl Fn() {
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/associated-types/normalization-ice-issue-149746.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ trait Owner { type Ty<T: FnMut()>; }
impl Owner for () { type Ty<T: FnMut()> = T; }
pub struct Warns<T> {
_significant_drop: <() as Owner>::Ty<T>,
//~^ ERROR expected an `FnMut()` closure, found `T`
//~^ ERROR expected `FnMut()` signature, found `T`
field: String,
}
pub fn test<T>(w: Warns<T>) {
//~^ ERROR expected an `FnMut()` closure, found `T`
//~^ ERROR expected `FnMut()` signature, found `T`
_ = || w.field
//~^ ERROR expected an `FnMut()` closure, found `T`
//~| ERROR expected an `FnMut()` closure, found `T`
//~^ ERROR expected `FnMut()` signature, found `T`
//~| ERROR expected `FnMut()` signature, found `T`
//~| WARN: changes to closure capture in Rust 2021 will affect drop order
}
fn main() {}
16 changes: 8 additions & 8 deletions tests/ui/associated-types/normalization-ice-issue-149746.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0277]: expected an `FnMut()` closure, found `T`
error[E0277]: expected `FnMut()` signature, found `T`
--> $DIR/normalization-ice-issue-149746.rs:6:24
|
LL | _significant_drop: <() as Owner>::Ty<T>,
| ^^^^^^^^^^^^^^^^^^^^ expected an `FnMut()` closure, found `T`
| ^^^^^^^^^^^^^^^^^^^^ expected `FnMut()` signature, found `T`
|
= note: wrap the `T` in a closure with no arguments: `|| { /* code */ }`
note: required by a bound in `Owner::Ty`
Expand Down Expand Up @@ -35,11 +35,11 @@ help: add a dummy let to cause `w` to be fully captured
LL | _ = || { let _ = &w; w.field }
| +++++++++++++ +

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

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

error[E0277]: expected an `FnMut()` closure, found `T`
error[E0277]: expected `FnMut()` signature, found `T`
--> $DIR/normalization-ice-issue-149746.rs:12:9
|
LL | _ = || w.field
| ^^^^^^^^^^ expected an `FnMut()` closure, found `T`
| ^^^^^^^^^^ expected `FnMut()` signature, found `T`
|
= note: wrap the `T` in a closure with no arguments: `|| { /* code */ }`
note: required by a bound in `Owner::Ty`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/async-fn/impl-header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ impl async Fn<()> for F {}
//~^ ERROR `async` trait implementations are unsupported
//~| ERROR the precise format of `Fn`-family traits' type parameters is subject to change
//~| ERROR manual implementations of `Fn` are experimental
//~| ERROR expected an `FnMut()` closure, found `F`
//~| ERROR expected `FnMut()` signature, found `F`
//~| ERROR not all trait items implemented, missing: `call`

fn main() {}
4 changes: 2 additions & 2 deletions tests/ui/async-await/async-fn/impl-header.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ LL | impl async Fn<()> for F {}
|
= help: implement the missing item: `fn call(&self, _: ()) -> <Self as FnOnce<()>>::Output { todo!() }` (unstable, requires feature `fn_traits`)

error[E0277]: expected an `FnMut()` closure, found `F`
error[E0277]: expected `FnMut()` signature, found `F`
--> $DIR/impl-header.rs:5:23
|
LL | impl async Fn<()> for F {}
| ^ expected an `FnMut()` closure, found `F`
| ^ expected `FnMut()` signature, found `F`
|
help: the trait `FnMut()` is not implemented for `F`
--> $DIR/impl-header.rs:3:1
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/cast/raw-ptr-to-dyn-fn-raw-ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ fn main() {
let ptr: *mut () = core::ptr::null_mut();
let _: &mut dyn Fn() = unsafe {
&mut *(ptr as *mut dyn Fn())
//~^ ERROR expected an `Fn()` closure, found `()`
//~^ ERROR expected `Fn()` signature, found `()`
};
}
4 changes: 2 additions & 2 deletions tests/ui/cast/raw-ptr-to-dyn-fn-raw-ptr.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0277]: expected an `Fn()` closure, found `()`
error[E0277]: expected `Fn()` signature, found `()`
--> $DIR/raw-ptr-to-dyn-fn-raw-ptr.rs:6:16
|
LL | &mut *(ptr as *mut dyn Fn())
| ^^^ expected an `Fn()` closure, found `()`
| ^^^ expected `Fn()` signature, found `()`
|
= help: the trait `Fn()` is not implemented for `()`
= note: wrap the `()` in a closure with no arguments: `|| { /* code */ }`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/closures/closure-expected.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() {
let x = Some(1);
let y = x.or_else(4);
//~^ ERROR expected an `FnOnce()` closure, found `{integer}`
//~^ ERROR expected `FnOnce()` signature, found `{integer}`
}
4 changes: 2 additions & 2 deletions tests/ui/closures/closure-expected.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0277]: expected an `FnOnce()` closure, found `{integer}`
error[E0277]: expected `FnOnce()` signature, found `{integer}`
--> $DIR/closure-expected.rs:3:23
|
LL | let y = x.or_else(4);
| ------- ^ expected an `FnOnce()` closure, found `{integer}`
| ------- ^ expected `FnOnce()` signature, found `{integer}`
| |
| required by a bound introduced by this call
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ note: required by a bound in `req_fn`
LL | fn req_fn(_: impl Fn(&'static str) -> String) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `req_fn`

error[E0277]: expected an `Fn(&'static str)` closure, found `&mut {closure@$DIR/closure-ref-fn-kind-mismatch-issue-161327.rs:45:28: 45:45}`
error[E0277]: expected `Fn(&'static str)` signature, found `&mut {closure@$DIR/closure-ref-fn-kind-mismatch-issue-161327.rs:45:28: 45:45}`
--> $DIR/closure-ref-fn-kind-mismatch-issue-161327.rs:46:12
|
LL | req_fn(&mut pure_closure);
| ------ ^^^^^^^^^^^^^^^^^ expected an `Fn(&'static str)` closure, found `&mut {closure@$DIR/closure-ref-fn-kind-mismatch-issue-161327.rs:45:28: 45:45}`
| ------ ^^^^^^^^^^^^^^^^^ expected `Fn(&'static str)` signature, found `&mut {closure@$DIR/closure-ref-fn-kind-mismatch-issue-161327.rs:45:28: 45:45}`
| |
| required by a bound introduced by this call
|
Expand All @@ -99,11 +99,11 @@ LL - req_fn(&mut pure_closure);
LL + req_fn(pure_closure);
|

error[E0277]: expected an `Fn(&'static str)` closure, found `&mut {closure@$DIR/closure-ref-fn-kind-mismatch-issue-161327.rs:53:21: 53:25}`
error[E0277]: expected `Fn(&'static str)` signature, found `&mut {closure@$DIR/closure-ref-fn-kind-mismatch-issue-161327.rs:53:21: 53:25}`
--> $DIR/closure-ref-fn-kind-mismatch-issue-161327.rs:59:12
|
LL | req_fn(&mut outer);
| ------ ^^^^^^^^^^ expected an `Fn(&'static str)` closure, found `&mut {closure@$DIR/closure-ref-fn-kind-mismatch-issue-161327.rs:53:21: 53:25}`
| ------ ^^^^^^^^^^ expected `Fn(&'static str)` signature, found `&mut {closure@$DIR/closure-ref-fn-kind-mismatch-issue-161327.rs:53:21: 53:25}`
| |
| required by a bound introduced by this call
|
Expand All @@ -119,11 +119,11 @@ LL - req_fn(&mut outer);
LL + req_fn(outer);
|

error[E0277]: expected an `Fn(&'static str)` closure, found `&mut {closure@$DIR/closure-ref-fn-kind-mismatch-issue-161327.rs:65:17: 65:21}`
error[E0277]: expected `Fn(&'static str)` signature, found `&mut {closure@$DIR/closure-ref-fn-kind-mismatch-issue-161327.rs:65:17: 65:21}`
--> $DIR/closure-ref-fn-kind-mismatch-issue-161327.rs:69:12
|
LL | req_fn(&mut c);
| ------ ^^^^^^ expected an `Fn(&'static str)` closure, found `&mut {closure@$DIR/closure-ref-fn-kind-mismatch-issue-161327.rs:65:17: 65:21}`
| ------ ^^^^^^ expected `Fn(&'static str)` signature, found `&mut {closure@$DIR/closure-ref-fn-kind-mismatch-issue-161327.rs:65:17: 65:21}`
| |
| required by a bound introduced by this call
|
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/closures/coerce-unsafe-to-closure.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0277]: expected an `FnOnce(&str)` closure, found `unsafe fn(_) -> _ {std::intrinsics::transmute::<_, _>}`
error[E0277]: expected `FnOnce(&str)` signature, found `unsafe fn(_) -> _ {std::intrinsics::transmute::<_, _>}`
--> $DIR/coerce-unsafe-to-closure.rs:2:44
|
LL | let x: Option<&[u8]> = Some("foo").map(std::mem::transmute);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
let number = 2;
Some(true).filter({ //~ ERROR expected an `FnOnce(&bool)` closure, found `bool`
Some(true).filter({ //~ ERROR expected `FnOnce(&bool)` signature, found `bool`
if number % 2 == 0 {
number == 0
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0277]: expected an `FnOnce(&bool)` closure, found `bool`
error[E0277]: expected `FnOnce(&bool)` signature, found `bool`
--> $DIR/block_instead_of_closure_in_arg.rs:3:23
|
LL | Some(true).filter({
Expand All @@ -12,7 +12,7 @@ LL | || number != 0
LL | || }
| ||_________- this tail expression is of type `bool`
LL | | });
| |______^ expected an `FnOnce(&bool)` closure, found `bool`
| |______^ expected `FnOnce(&bool)` signature, found `bool`
|
= help: the trait `for<'a> FnOnce(&'a bool)` is not implemented for `bool`
note: required by a bound in `Option::<T>::filter`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const x: usize =42;
fn main() {
let p = Some(45).and_then({|x| //~ ERROR expected an `FnOnce({integer})` closure, found `Option<usize>`
let p = Some(45).and_then({|x| //~ ERROR expected `FnOnce({integer})` signature, found `Option<usize>`
1 + 1;
Some(x * 2)
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0277]: expected an `FnOnce({integer})` closure, found `Option<usize>`
error[E0277]: expected `FnOnce({integer})` signature, found `Option<usize>`
--> $DIR/ruby_style_closure_successful_parse.rs:3:31
|
LL | let p = Some(45).and_then({|x|
Expand All @@ -9,7 +9,7 @@ LL | | 1 + 1;
LL | | Some(x * 2)
| | ----------- this tail expression is of type `Option<usize>`
LL | | });
| |_____^ expected an `FnOnce({integer})` closure, found `Option<usize>`
| |_____^ expected `FnOnce({integer})` signature, found `Option<usize>`
|
= help: the trait `FnOnce({integer})` is not implemented for `Option<usize>`
note: required by a bound in `Option::<T>::and_then`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/extern/extern-wrong-value-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ fn main() {
// extern functions are extern "C" fn
let _x: extern "C" fn() = f; // OK
is_fn(f);
//~^ ERROR expected an `Fn()` closure, found `extern "C" fn() {f}`
//~^ ERROR expected `Fn()` signature, found `extern "C" fn() {f}`
}
4 changes: 2 additions & 2 deletions tests/ui/extern/extern-wrong-value-type.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0277]: expected an `Fn()` closure, found `extern "C" fn() {f}`
error[E0277]: expected `Fn()` signature, found `extern "C" fn() {f}`
--> $DIR/extern-wrong-value-type.rs:9:11
|
LL | is_fn(f);
| ----- ^ expected an `Fn()` closure, found `extern "C" fn() {f}`
| ----- ^ expected `Fn()` signature, found `extern "C" fn() {f}`
| |
| required by a bound introduced by this call
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct Foo;
impl Fn<()> for Foo {
//~^ ERROR the precise format of `Fn`-family traits' type parameters is subject to change
//~| ERROR manual implementations of `Fn` are experimental
//~| ERROR expected an `FnMut()` closure, found `Foo`
//~| ERROR expected `FnMut()` signature, found `Foo`
extern "rust-call" fn call(self, args: ()) -> () {}
//~^ ERROR "rust-call" ABI is experimental and subject to change
//~| ERROR `call` has an incompatible type for trait
Expand All @@ -26,7 +26,7 @@ struct Bar;
impl FnMut<()> for Bar {
//~^ ERROR the precise format of `Fn`-family traits' type parameters is subject to change
//~| ERROR manual implementations of `FnMut` are experimental
//~| ERROR expected an `FnOnce()` closure, found `Bar`
//~| ERROR expected `FnOnce()` signature, found `Bar`
extern "rust-call" fn call_mut(&self, args: ()) -> () {}
//~^ ERROR "rust-call" ABI is experimental and subject to change
//~| ERROR incompatible type for trait
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ LL | impl FnMut<()> for Bar {
|
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable

error[E0277]: expected an `FnMut()` closure, found `Foo`
error[E0277]: expected `FnMut()` signature, found `Foo`
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:9:17
|
LL | impl Fn<()> for Foo {
| ^^^ expected an `FnMut()` closure, found `Foo`
| ^^^ expected `FnMut()` signature, found `Foo`
|
help: the trait `FnMut()` is not implemented for `Foo`
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:8:1
Expand Down Expand Up @@ -161,11 +161,11 @@ help: change the self-receiver type to match the trait
LL | extern "rust-call" fn call_mut(&mut self, args: ()) -> () {}
| +++

error[E0277]: expected an `FnOnce()` closure, found `Bar`
error[E0277]: expected `FnOnce()` signature, found `Bar`
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:26:20
|
LL | impl FnMut<()> for Bar {
| ^^^ expected an `FnOnce()` closure, found `Bar`
| ^^^ expected `FnOnce()` signature, found `Bar`
|
help: the trait `FnOnce()` is not implemented for `Bar`
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:25:1
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/fn/fn-trait-formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ fn main() {
//~| NOTE found struct `Box<dyn FnMut() -> isize>`

needs_fn(1);
//~^ ERROR expected an `Fn(isize)` closure, found `{integer}`
//~^ ERROR expected `Fn(isize)` signature, found `{integer}`
}
4 changes: 2 additions & 2 deletions tests/ui/fn/fn-trait-formatting.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ LL | let _: () = Box::new(|| -> isize { unimplemented!() }) as Box<dyn FnMut
= note: expected unit type `()`
found struct `Box<dyn FnMut() -> isize>`

error[E0277]: expected an `Fn(isize)` closure, found `{integer}`
error[E0277]: expected `Fn(isize)` signature, found `{integer}`
--> $DIR/fn-trait-formatting.rs:19:14
|
LL | needs_fn(1);
| -------- ^ expected an `Fn(isize)` closure, found `{integer}`
| -------- ^ expected `Fn(isize)` signature, found `{integer}`
| |
| required by a bound introduced by this call
|
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/fn/issue-39259.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct S;

impl Fn(u32) -> u32 for S {
//~^ ERROR associated item constraints are not allowed here [E0229]
//~| ERROR expected an `FnMut(u32)` closure, found `S`
//~| ERROR expected `FnMut(u32)` signature, found `S`
fn call(&self) -> u32 {
//~^ ERROR method `call` has 1 parameter but the declaration in trait `call` has 2
5
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/fn/issue-39259.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ help: add the missing parameter from the trait
LL | fn call(&self, args: Args) -> u32 {
| ++++++++++++

error[E0277]: expected an `FnMut(u32)` closure, found `S`
error[E0277]: expected `FnMut(u32)` signature, found `S`
--> $DIR/issue-39259.rs:6:25
|
LL | impl Fn(u32) -> u32 for S {
| ^ expected an `FnMut(u32)` closure, found `S`
| ^ expected `FnMut(u32)` signature, found `S`
|
help: the trait `FnMut(u32)` is not implemented for `S`
--> $DIR/issue-39259.rs:4:1
Expand Down
Loading
Loading