Associated const equality conflicts with associated type equality · Issue #112560 · rust-lang/rust (original) (raw)

I tried this code and it compiled:

trait Trait2 {}

trait Trait1 { const A: u32; type A; }

impl<T: Trait1<A = u32>, const N: usize> Trait2 for [T; N] {}

fn main() {}

Then I tried this code and it didn't compile:

#![feature(associated_const_equality)]

trait Trait2 {}

trait Trait1 { const A: u32; type A; }

impl<T: Trait1<A = 12>, const N: usize> Trait2 for [T; N] {}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.72.0-nightly (37998ab50 2023-06-11)
binary: rustc
commit-hash: 37998ab508d5d9fa0d465d7b535dc673087dda8f
commit-date: 2023-06-11
host: aarch64-apple-darwin
release: 1.72.0-nightly
LLVM version: 16.0.5

Backtrace

error: expected associated type bound, found constant
  --> src/main.rs:10:16
   |
10 | impl<T: Trait1<A = 12>, const N: usize> Trait2 for [T; N] {}
   |                ^^^^^^
   |
note: associated type defined here
  --> src/main.rs:5:5
   |
5  |     type A;
   |     ^^^^^^

error: could not compile `proba2` (bin "proba2") due to previous error

Explanation

Rust allows for associated const parameter and associated type parameter to have the same name. So, I expected there would be some way to disambiguate which one I'm referring to when setting the equality constraint but haven't found a way to do so.

This problem is related to Associated Const Equality