Closed
Description
While you can coerce closures to fn
pointers, it is currently not possible to coerce closures to unsafe fn
pointers since that requires a transitive coercion from fn
pointers to unsafe fn
pointers. We do not allow transitive coercions. Example:
static A: fn() = || {}; // OK
static B: unsafe fn() = A; // OK
static C: unsafe fn() = || {}; // ERROR; would require the two coercions above transitively.
This behavior of current Rust was unexpected in rust-lang/rfcs#2592 (comment).
@cramertj had the idea to implement an immediately attainable direct coercion between closures and unsafe fn
pointers rather than go the more complex and contentious route of transitive coercions (which may have unforeseen consequences). This idea seems reasonable to me.
PS: should we fcp the PR once made?