Skip to content

Associated const equality conflicts with associated type equality #112560

Closed
@mversic

Description

@mversic

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

Metadata

Metadata

Assignees

Labels

A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-associated_const_equality`#![feature(associated_const_equality)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team, which will review and decide on the PR/issue.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions