-
Couldn't load subscription status.
- Fork 13.9k
Closed
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsA-inferenceArea: Type inferenceArea: Type inferenceA-type-systemArea: Type systemArea: Type systemC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-langRelevant to the language teamRelevant to the language team
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?
Metadata
Metadata
Assignees
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsA-inferenceArea: Type inferenceArea: Type inferenceA-type-systemArea: Type systemArea: Type systemC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-langRelevant to the language teamRelevant to the language team