I tried this code:
#![expect(incomplete_features, reason = "generic_const_*")]
#![feature(
min_generic_const_args,
generic_const_args,
generic_const_items,
)]
type const U32_TO_USIZE<const N: u32>: usize = const { N as usize };
trait Trait {}
impl<const SIZE: u32, T> Trait for [T; U32_TO_USIZE::<SIZE>] {}
I expected to see this happen: Code compiles with RUSTFLAGS="-Znext-solver=globally" cargo build
Instead, this happened:
error[E0207]: the const parameter `SIZE` is not constrained by the impl trait, self type, or predicates
--> *.rs
|
222 | impl<const SIZE: u32, T> Trait for [T; U32_TO_USIZE::<SIZE>] {}
| ^^^^^^^^^^^^^^^ unconstrained const parameter
|
= note: expressions using a const parameter must map each value to a distinct output value
= note: proving the result of expressions other than the parameter are unique is not supported
Very similar code compiles:
trait Trait {}
impl<const SIZE: usize, T> Trait for [T; SIZE] {}
So compiler treating SIZE as unconstrained is clearly a bug.
I found a few bug reports with similar message, but they weren't exactly the same.
Meta
rustc --version --verbose:
rustc 1.97.0-nightly (9eb3be26b 2026-05-18)
binary: rustc
commit-hash: 9eb3be26b46eccea1de7448ea9cc3c1d20bb1a35
commit-date: 2026-05-18
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.4
I tried this code:
I expected to see this happen: Code compiles with
RUSTFLAGS="-Znext-solver=globally" cargo buildInstead, this happened:
Very similar code compiles:
So compiler treating
SIZEas unconstrained is clearly a bug.I found a few bug reports with similar message, but they weren't exactly the same.
Meta
rustc --version --verbose: