Skip to content

References/borrows of const values don't have 'static lifetime #40522

Closed
@mzji

Description

@mzji

Example:

const FOO: usize = 0;

fn bar() -> &'static usize {
    &FOO
}

fn main() {
    bar();
}

Get error:

rustc 1.17.0-nightly (b1e31766d 2017-03-03)
error: borrowed value does not live long enough
 --> <anon>:5:6
  |
5 |     &FOO
  |      ^^^ does not live long enough
6 | }
  | - temporary value only lives until here
  |
  = note: borrowed value must be valid for the static lifetime...

error: aborting due to previous error

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