Repository navigation
GCA: associated constant is not normalized properly in generic argument #161264
Copy link
Copy link
Closed
Closed
Copy link
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-gca_const_items`#![feature(gca_const_items)]` (previously: `generic_const_args`)`#![feature(gca_const_items)]` (previously: `generic_const_args`)F-gca_min_const_items`#![feature(gca_min_const_items)]` (previously: `min_generic_const_args`)`#![feature(gca_min_const_items)]` (previously: `min_generic_const_args`)
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-gca_const_items`#![feature(gca_const_items)]` (previously: `generic_const_args`)`#![feature(gca_const_items)]` (previously: `generic_const_args`)F-gca_min_const_items`#![feature(gca_min_const_items)]` (previously: `min_generic_const_args`)`#![feature(gca_min_const_items)]` (previously: `min_generic_const_args`)
Activity
Add the dispatch plan and handoff, with the plan corrected against wh…
Rebase on `main` and bring both documents up to date with what shipped
Rollup merge of rust-lang#161929 - khyperia:explicitly-track-inherent…
Rollup merge of rust-lang#161929 - khyperia:explicitly-track-inherent…
Rollup merge of rust-lang#161929 - khyperia:explicitly-track-inherent…
Rollup merge of rust-lang#161929 - khyperia:explicitly-track-inherent…
Rollup merge of rust-lang#161929 - khyperia:explicitly-track-inherent…
Rollup merge of rust-lang#161929 - khyperia:explicitly-track-inherent…
Rollup merge of rust-lang#161929 - khyperia:explicitly-track-inherent…
Rollup merge of rust-lang#161929 - khyperia:explicitly-track-inherent…
Rollup merge of rust-lang#161929 - khyperia:explicitly-track-inherent…
9 remaining items
Rollup merge of rust-lang#162179 - khyperia:direct-rhs-const, r=BoxyUwU
Rollup merge of rust-lang#162179 - khyperia:direct-rhs-const, r=BoxyUwU
Rollup merge of rust-lang#162179 - khyperia:direct-rhs-const, r=BoxyUwU
Rollup merge of rust-lang#162179 - khyperia:direct-rhs-const, r=BoxyUwU
Rollup merge of rust-lang#162179 - khyperia:direct-rhs-const, r=BoxyUwU
Rollup merge of rust-lang#162179 - khyperia:direct-rhs-const, r=BoxyUwU
Rollup merge of rust-lang#162179 - khyperia:direct-rhs-const, r=BoxyUwU
Unrolled build for #162179 in rollup 162310
Rollup merge of #162179 - khyperia:direct-rhs-const, r=BoxyUwU
Rollup merge of #162179 - khyperia:direct-rhs-const, r=BoxyUwU
Rollup merge of #162179 - khyperia:direct-rhs-const, r=BoxyUwU
Rollup merge of rust-lang#161929 - khyperia:explicitly-track-inherent…
Rollup merge of #161929 - khyperia:explicitly-track-inherent-args, r=…