rust/tests/ui/fn/fn-trait-formatting.stderr
Esteban Küber e6bd6c2044 Use parenthetical notation for Fn traits
Always use the `Fn(T) -> R` format when printing closure traits instead of `Fn<(T,), Output = R>`.

Fix #67100:

```
error[E0277]: expected a `Fn()` closure, found `F`
 --> file.rs:6:13
  |
6 |     call_fn(f)
  |     ------- ^ expected an `Fn()` closure, found `F`
  |     |
  |     required by a bound introduced by this call
  |
  = note: wrap the `F` in a closure with no arguments: `|| { /* code */ }`
note: required by a bound in `call_fn`
 --> file.rs:1:15
  |
1 | fn call_fn<F: Fn() -> ()>(f: &F) {
  |               ^^^^^^^^^^ required by this bound in `call_fn`
help: consider further restricting this bound
  |
5 | fn call_any<F: std::any::Any + Fn()>(f: &F) {
  |                              ++++++
```
2024-05-29 22:26:54 +00:00

61 lines
2.5 KiB
Plaintext

error[E0308]: mismatched types
--> $DIR/fn-trait-formatting.rs:6:17
|
LL | let _: () = Box::new(|_: isize| {}) as Box<dyn FnOnce(isize)>;
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `Box<dyn FnOnce(isize)>`
| |
| expected due to this
|
= note: expected unit type `()`
found struct `Box<dyn FnOnce(isize)>`
help: use parentheses to call this trait object
|
LL | let _: () = (Box::new(|_: isize| {}) as Box<dyn FnOnce(isize)>)(/* isize */);
| + ++++++++++++++
error[E0308]: mismatched types
--> $DIR/fn-trait-formatting.rs:10:17
|
LL | let _: () = Box::new(|_: isize, isize| {}) as Box<dyn Fn(isize, isize)>;
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `Box<dyn Fn(isize, isize)>`
| |
| expected due to this
|
= note: expected unit type `()`
found struct `Box<dyn Fn(isize, isize)>`
help: use parentheses to call this trait object
|
LL | let _: () = (Box::new(|_: isize, isize| {}) as Box<dyn Fn(isize, isize)>)(/* isize */, /* isize */);
| + +++++++++++++++++++++++++++
error[E0308]: mismatched types
--> $DIR/fn-trait-formatting.rs:14:17
|
LL | let _: () = Box::new(|| -> isize { unimplemented!() }) as Box<dyn FnMut() -> isize>;
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `Box<dyn FnMut() -> isize>`
| |
| expected due to this
|
= note: expected unit type `()`
found struct `Box<dyn FnMut() -> isize>`
error[E0277]: expected a `Fn(isize)` closure, found `{integer}`
--> $DIR/fn-trait-formatting.rs:19:14
|
LL | needs_fn(1);
| -------- ^ expected an `Fn(isize)` closure, found `{integer}`
| |
| required by a bound introduced by this call
|
= help: the trait `Fn(isize)` is not implemented for `{integer}`
note: required by a bound in `needs_fn`
--> $DIR/fn-trait-formatting.rs:1:31
|
LL | fn needs_fn<F>(x: F) where F: Fn(isize) -> isize {}
| ^^^^^^^^^^^^^^^^^^ required by this bound in `needs_fn`
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.