Skip to content

the const parameter SIZE is not constrained by the impl trait, self type, or predicates #156745

@nazar-pc

Description

@nazar-pc

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-generic_const_args`#![feature(generic_const_args)]`F-generic_const_items`#![feature(generic_const_items)]`F-min_generic_const_args`#![feature(min_generic_const_args)]`needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions