Closed
Description
openedon Mar 20, 2019
This compiles (playground):
pub fn bar(mut x: Box<dyn FnMut()>) {
foo(|| x())
}
pub fn foo<T: FnOnce()>(_: T) {}
but clippy suggests:
warning: redundant closure found
--> src/lib.rs:2:9
|
2 | foo(|| x())
| ^^^^^^ help: remove closure as shown: `x`
|
= note: #[warn(clippy::redundant_closure)] on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
which fails to compile with (playground):
error[E0277]: expected a `std::ops::FnOnce<()>` closure, found `std::boxed::Box<dyn std::ops::FnMut()>`
--> src/lib.rs:2:5
|
2 | foo(x)
| ^^^ expected an `FnOnce<()>` closure, found `std::boxed::Box<dyn std::ops::FnMut()>`
|
= help: the trait `std::ops::FnOnce<()>` is not implemented for `std::boxed::Box<dyn std::ops::FnMut()>`
= note: wrap the `std::boxed::Box<dyn std::ops::FnMut()>` in a closure with no arguments: `|| { /* code */ }
note: required by `foo`
--> src/lib.rs:5:1
|
5 | pub fn foo<T: FnOnce()>(_: T) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment