Closed
Description
Given that non-capturing closures coerce to fn
, and fn
coerces to unsafe fn
, I would expect the transitive step to also happen -- but it does not:
fn coerce(_x: fn()) {}
fn coerce_unsafe(_x: unsafe fn()) {}
fn foo() {}
fn main() {
coerce(|| panic!()); // works
coerce_unsafe(foo); // works
coerce_unsafe(|| panic!()); // fails
}
error[E0308]: mismatched types
--> src/main.rs:9:19
|
9 | coerce_unsafe(|| panic!());
| ^^^^^^^^^^^ expected unsafe fn, found normal fn
|
= note: expected type `unsafe fn()`
found type `[closure@src/main.rs:9:19: 9:30]`
This is particularly annoying when instantiating RawWakerVTable
, because it means one cannot just use closure syntax there.