Skip to content

Unable to infer the type of a ~fn inside an Option #9409

Closed
@MicahChalmer

Description

@MicahChalmer

There seems to be no way to use a ~fn inside an Option without rewriting the type every time you use it. This line:

let _:Option<~fn()> = Some(|| { });

gives this error message:

error: mismatched types: expected `std::option::Option<~fn:Send()>` but found `std::option::Option<&fn<no-bounds>()>` (expected ~ closure, found & closure)

The problem is that the function inside the Some is interpreted to be a &fn rather than a ~fn, and then the compiler complains about a type mismatch. The only way to make it work is this to make it Some::<~fn()>(|| { }) instead. But when the function isn't just ~fn() and has parameters and a return type, that becomes extremely annoying.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions