Skip to content

wrong "borrowed value does not live long enough" for singleton struct #13887

Closed
@stepancheg

Description

@stepancheg

Code:

trait Foo {}

struct Bar;

impl Foo for Bar {}

fn main() {
    &'static Bar as &'static Foo;
}

Compiler incorrectly reports that values does not live long enough:

tmp2.rs:8:5: 8:17 error: borrowed value does not live long enough
tmp2.rs:8     &'static Bar as &'static Foo;
              ^~~~~~~~~~~~
note: reference must be valid for the static lifetime...
tmp2.rs:8:5: 8:33 note: ...but borrowed value is only valid for the statement at 8:4
tmp2.rs:8     &'static Bar as &'static Foo;
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

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