Skip to content

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

@nazar-pc

Description

@nazar-pc

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions