Skip to content

GCA: associated constant is not normalized properly in generic argument #161264

Description

@nazar-pc

I tried this code:

#![allow(incomplete_features)]
#![feature(generic_const_args, min_generic_const_args, macroless_generic_const_args)]

struct Buffer<const N: usize>([u8; N]);

trait Trait {
    const N: usize;

    fn get(&self) -> &Buffer<{ Self::N }>;
}

impl<T> Trait for &mut T
where
    T: Trait,
{
    const N: usize = T::N;

    fn get(&self) -> &Buffer<{ Self::N }> {
        T::get(self)
    }
}

I expected to see this happen: code compiles.

Instead, this happened:

$ RUSTFLAGS="-Znext-solver=globally" cargo +nightly check
error[E0308]: mismatched types
  --> src/lib.rs:18:9
   |
12 | impl<T> Trait for &mut T
   |      - found this type parameter
...
18 |     fn get(&self) -> &Buffer<{ Self::N }> {
   |                      -------------------- expected `&Buffer<<&mut T as Trait>::N>` because of return type
19 |         T::get(self)
   |         ^^^^^^^^^^^^ expected `&Buffer<<&mut T as Trait>::N>`, found `&Buffer<<T as Trait>::N>`
   |
   = note: expected reference `&Buffer<<&mut T as Trait>::N>`
              found reference `&Buffer<<T as Trait>::N>`

For more information about this error, try `rustc --explain E0308`.

I've hit multiple variations of this error, for example here is another one:

#![allow(incomplete_features)]
#![feature(generic_const_args, inherent_associated_types, macroless_generic_const_args, min_generic_const_args)]

trait Foo {
    const N: usize;
    fn get(&self) -> &[u8; Self::N];
}

struct Bar<const N: usize>([u8; N]);

impl<const N: usize> Foo for Bar<N> {
    const N: usize = N;
    fn get(&self) -> &[u8; Self::N] {
        &self.0
    }
}
error[E0308]: mismatched types
  --> src/lib.rs:14:9
   |
13 |     fn get(&self) -> &[u8; Self::N] {
   |                      -------------- expected `&[u8; <Bar<N> as Foo>::N]` because of return type
14 |         &self.0
   |         ^^^^^^^ expected an array with a size of <Bar<N> as Foo>::N, found one with a size of N

For more information about this error, try `rustc --explain E0308`.

Not being able to use such constructions causes great difficulties in several places for me.

Meta

rustc --version --verbose:

rustc 1.100.0-nightly (34baba539 2026-08-16)
binary: rustc
commit-hash: 34baba5394fcbda4cba7b7c1964a6db421c77c91
commit-date: 2026-08-16
host: x86_64-unknown-linux-gnu
release: 1.100.0-nightly
LLVM version: 23.1.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-gca_const_items`#![feature(gca_const_items)]` (previously: `generic_const_args`)F-gca_min_const_items`#![feature(gca_min_const_items)]` (previously: `min_generic_const_args`)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions