Skip to content

Literals don't have static lifetime #40405

Closed
@jethrogb

Description

@jethrogb

OK:

fn get_slice_ok() -> &'static [u8] {
    const CONST: &'static [u8] = &[0];
    CONST
}

Borrowck error:

fn get_slice_error() -> &'static [u8] {
    &[0]
}

But consts and literals are basically the same thing, so I'd expect this to work.

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