rust-lang / rust-lang/rust

generic_const_exprs: the type `[(); N]` does not fulfill the required lifetime

Open
#150,778 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-generic_const_exprs needs-triage T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

#![feature(generic_const_exprs)]

const N: usize = 32;

pub trait IoType: 'static {
    type PointerType;
}
impl<const SIZE: usize> IoType for [(); SIZE] {
    type PointerType = ();
}

struct InternalArgs<'a> {
    ptr: <[(); N] as IoType>::PointerType,
    _phantom: core::marker::PhantomData<&'a ()>,
}

I expected to see this happen: Must compile successfully

Instead, this happened:

error[E0477]: the type `[(); N]` does not fulfill the required lifetime
  --> src/main.rs:14:10
   |
14 |     ptr: <[(); N] as IoType>::PointerType,
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: type must satisfy the static lifetime

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=123ce068ffb25c66c9a902482a7227eb

The same code compiles with any one of the following changes:

  • Remove generic_const_exprs feature
  • Remove 'static from trait bounds
  • Remove 'a lifetime from a struct
  • Replace N with the value itself

Simply enabling and not even taking advantage of generic_const_exprs feature is sufficient to confuse the compiler. Without it code compiles even on stable Rust.

Meta

rustc --version --verbose:

rustc 1.94.0-nightly (8d670b93d 2025-12-31)
binary: rustc
commit-hash: 8d670b93d40737e1b320fd892c6f169ffa35e49e
commit-date: 2025-12-31
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.8

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example from src/main.rs on the reported nightly compiler and compare it with the listed minimal changes. Investigate how the compiler handles the static lifetime requirement for the associated type projection involving [(); N] and generic_const_exprs; done means the original example compiles without those workarounds.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.