Skip to content

Lifetime of fn() converted to &Fn() isn't long enough #28546

Closed
@eefriedman

Description

@eefriedman
fn double(x: i32) -> i32 { x * 2 }
fn get_double_func() -> &'static (Fn(i32) -> i32)
{
    // Works
    const GET_DOUBLE_FUNC: &'static (Fn(i32) -> i32) = &double;
    GET_DOUBLE_FUNC
}
fn get_double_func_2() -> &'static (Fn(i32) -> i32)
{
    // Error message
    &double
}
fn main() {}

It would be nice if the lifetime of &double were the same in all contexts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions