Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Non-'static Lifetimes in Const Generics #74052

Open
yodaldevoid opened this issue Jul 5, 2020 · 3 comments
Open

Non-'static Lifetimes in Const Generics #74052

yodaldevoid opened this issue Jul 5, 2020 · 3 comments
Labels
A-const-generics Area: const generics (parameters and arguments) A-lifetimes Area: Lifetimes / regions C-enhancement Category: An issue proposing an enhancement or a PR with one. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@yodaldevoid
Copy link
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

@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) A-lifetimes Area: Lifetimes / regions F-const_generics `#![feature(const_generics)]` T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Jul 5, 2020
@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 5, 2020
@nikomatsakis
Copy link
Contributor

This is "just" an implementation limitation, correct?

@lcnr
Copy link
Contributor

lcnr commented Jul 16, 2020

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 😆

github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Jul 23, 2020
=== stdout ===
=== stderr ===
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/56445-2.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #44580 <rust-lang/rust#44580> for more information

error[E0771]: use of non-static lifetime `'a` in const generic
 --> /home/runner/work/glacier/glacier/ices/56445-2.rs:6:26
  |
6 | struct Bug<'a, const S: &'a str>(PhantomData<&'a ()>);
  |                          ^^
  |
  = note: for more information, see issue #74052 <rust-lang/rust#74052>

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0771`.
==============
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Jul 23, 2020
=== stdout ===
=== stderr ===
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/60814.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #44580 <rust-lang/rust#44580> for more information

error[E0771]: use of non-static lifetime `'a` in const generic
 --> /home/runner/work/glacier/glacier/ices/60814.rs:3:45
  |
3 | pub fn function_with_str<'a, const STRING: &'a str>() {
  |                                             ^^
  |
  = note: for more information, see issue #74052 <rust-lang/rust#74052>

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0771`.
==============
@BoxyUwU BoxyUwU added F-adt_const_params `#![feature(adt_const_params)]` and removed F-const_generics `#![feature(const_generics)]` labels Jun 28, 2022
@lcnr lcnr removed the F-adt_const_params `#![feature(adt_const_params)]` label Jun 28, 2022
@lcnr
Copy link
Contributor

lcnr commented Jun 28, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-lifetimes Area: Lifetimes / regions C-enhancement Category: An issue proposing an enhancement or a PR with one. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants