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.
cc @nikomatsakis @arielb1
PS: should we fcp the PR once made?
While you can coerce closures to
fnpointers, it is currently not possible to coerce closures tounsafe fnpointers since that requires a transitive coercion fromfnpointers tounsafe fnpointers. We do not allow transitive coercions. Example: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 fnpointers rather than go the more complex and contentious route of transitive coercions (which may have unforeseen consequences). This idea seems reasonable to me.cc @nikomatsakis @arielb1
PS: should we fcp the PR once made?