Skip to content

&[1, 2, 3] should always be &'static [<generic integer>] #12853

@thestinger

Description

@thestinger

The following works:

fn foo<'a>(xs: &'a [int]) -> &'a [int] {
    if xs.len() & 1 == 0 {
        static ys: &'static [int] = &[1, 2, 3];
        ys
    } else {
        xs
    }
}

This should also work, but does not:

fn foo<'a>(xs: &'a [int]) -> &'a [int] {
    if xs.len() & 1 == 0 {
        &[1, 2, 3]
    } else {
        xs
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions