Skip to content

Non-'static Lifetimes in Const Generics #74052

Open
@yodaldevoid

Description

@yodaldevoid
Contributor

We currently don't correctly handle non-'static lifetimes in const generics. Until #74051 is merged we ICE when a non-'static lifetime is hit, as seen in #60814.

Many uses for const generics does not hit this limitation, but the following case has been brought up:

fn test<'a, const VALUE: std::mem::Discriminant<Enum<'a>>(v: Enum<'a>) -> bool {
     std::mem::discriminant(&v) == VALUE
}

as quoted from @lcnr on Zulip

mem::Discriminant is invariant so VALUE has to be mem::Discriminant of Enum<'a> and can't use Enum<'static>.

@varkor @eddyb @nikomatsakis

Activity

added
A-const-genericsArea: const generics (parameters and arguments)
A-lifetimesArea: Lifetimes / regions
T-langRelevant to the language team
on Jul 5, 2020
added
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
on Jul 5, 2020
nikomatsakis

nikomatsakis commented on Jul 16, 2020

@nikomatsakis
Contributor

This is "just" an implementation limitation, correct?

lcnr

lcnr commented on Jul 16, 2020

@lcnr
Contributor

Mostly, it should be theoretically fine, but ends up with similar problems to what #74113 ended up solving.

It also has some open design questions IMO, which I don't want to care about for now 😆

added and removed on Jun 28, 2022
lcnr

lcnr commented on Jun 28, 2022

@lcnr
Contributor

const generics triage

This is part of generic const parameter types. The design work for that is tracked in rust-lang/project-const-generics#28.

1 remaining item

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-lifetimesArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nikomatsakis@yodaldevoid@jonas-schievink@BoxyUwU@JohnTitor

        Issue actions

          Non-'static Lifetimes in Const Generics · Issue #74052 · rust-lang/rust