Skip to content

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

Closed

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

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 17, 2026
  2. added
    F-gca_const_items`#![feature(gca_const_items)]` (previously: `generic_const_args`)
    on Aug 18, 2026
  3. added
    F-gca_min_const_items`#![feature(gca_min_const_items)]` (previously: `min_generic_const_args`)
    on Aug 28, 2026
  4. added 3 commits that reference this issue on Aug 31, 2026
  5. added a commit that references this issue on Aug 31, 2026
  6. added a commit that references this issue on Aug 31, 2026
  7. added 2 commits that reference this issue on Sep 1, 2026
  8. added 2 commits that reference this issue on Sep 1, 2026
  9. 9 remaining items

  10. added a commit that references this issue on Sep 4, 2026
  11. added 5 commits that reference this issue on Sep 4, 2026
  12. added a commit that references this issue on Sep 4, 2026
  13. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 5, 2026
  14. added a commit that references this issue on Sep 5, 2026
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