Skip to content

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

@steveklabnik

Description

@steveklabnik

Issue by thestinger
Wednesday Mar 12, 2014 at 21:15 GMT

For earlier discussion, see rust-lang/rust#12853

This issue was labelled with: A-lifetimes in the Rust repository


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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions