Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
steveklabnik opened this issue Feb 11, 2015 · 0 comments · Fixed by #1414
Closed

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

steveklabnik opened this issue Feb 11, 2015 · 0 comments · Fixed by #1414

Comments

@steveklabnik
Copy link
Member

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
    }
}
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant