Open
Description
I have the following code:
#![feature(associated_const_equality)]
pub trait Align {
const ALIGN: usize;
}
impl<T> Align for T {
const ALIGN: usize = std::mem::size_of::<T>();
}
pub trait AlignedTo<const N: usize> {}
impl<T: Align<ALIGN=1>> AlignedTo<1> for T {}
impl<T: Align<ALIGN=2>> AlignedTo<2> for T {}
impl<T: Align<ALIGN=2>> AlignedTo<1> for T {}
impl<T: Align<ALIGN=4>> AlignedTo<4> for T {}
impl<T: Align<ALIGN=4>> AlignedTo<2> for T {}
impl<T: Align<ALIGN=4>> AlignedTo<1> for T {}
I would expect that this code would be accepted. While there are multiple blanket impls of AlignedTo<1>
and AlignedTo<2>
, they're bounded by mutually-exclusive bounds - e.g., a type cannot be both Align<ALIGN=1>
and Align<ALIGN=2>
at the same time. However, I get this error:
error[[E0119]](https://doc.rust-lang.org/nightly/error-index.html#E0119): conflicting implementations of trait `AlignedTo<1>`
--> src/lib.rs:15:1
|
13 | impl<T: Align<ALIGN=1>> AlignedTo<1> for T {}
| ------------------------------------------ first implementation here
14 | impl<T: Align<ALIGN=2>> AlignedTo<2> for T {}
15 | impl<T: Align<ALIGN=2>> AlignedTo<1> for T {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
error[[E0119]](https://doc.rust-lang.org/nightly/error-index.html#E0119): conflicting implementations of trait `AlignedTo<2>`
--> src/lib.rs:17:1
|
14 | impl<T: Align<ALIGN=2>> AlignedTo<2> for T {}
| ------------------------------------------ first implementation here
...
17 | impl<T: Align<ALIGN=4>> AlignedTo<2> for T {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
error[[E0119]](https://doc.rust-lang.org/nightly/error-index.html#E0119): conflicting implementations of trait `AlignedTo<1>`
--> src/lib.rs:18:1
|
13 | impl<T: Align<ALIGN=1>> AlignedTo<1> for T {}
| ------------------------------------------ first implementation here
...
18 | impl<T: Align<ALIGN=4>> AlignedTo<1> for T {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
Possibly related to #20400.
Version
Nightly 2022-10-19 4b8f431
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Can Do