Open
Description
Hi - apparently whenever there is a trait dependency chain which included bounded associated types and forms a double diamond pattern, such as the one illustrated in this figure, the type system fails with the error cannot satisfy `<Self as Red>::R == <Self as RedGreenBlue>::RGB`
, with the full backtrace reported below.
I tried to simplify as much as possible the issue and I documented it in this GitHub repository.
I boiled it down to this code, which you can try out at Rust playground:
pub trait Ancestor {
type A;
}
pub trait Red: Ancestor<A = <Self as Red>::R> {
type R;
}
pub trait Blue: Ancestor<A = <Self as Blue>::B> {
type B;
}
pub trait Green: Ancestor<A = <Self as Green>::G> {
type G;
}
pub trait RedGreen: Red<R = <Self as RedGreen>::RG> + Blue<B = <Self as RedGreen>::RG> {
type RG;
}
pub trait GreenBlue: Red<R = <Self as GreenBlue>::GB> + Green<G = <Self as GreenBlue>::GB> {
type GB;
}
pub trait RedGreenBlue:
RedGreen<RG = <Self as RedGreenBlue>::RGB> + GreenBlue<GB = <Self as RedGreenBlue>::RGB>
{
type RGB;
}
Meta
After having switched to nightly mode with rustup default nightly
and executed rustup update
, the error persists. Here is the output of executing rustc --version --verbose
on my system:
rustc 1.88.0-nightly (2fa8b11f0 2025-04-06)
binary: rustc
commit-hash: 2fa8b11f0933dae9b4e5d287cc10c989218e8b36
commit-date: 2025-04-06
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2
Backtrace
error[E0284]: type annotations needed
--> src/lib.rs:27:1
|
27 | / pub trait RedGreenBlue:
28 | | RedGreen<RG = <Self as RedGreenBlue>::RGB> + GreenBlue<GB = <Self as RedGreenBlue>::RGB>
| |____________________________________________________________________________________________^ cannot infer type
|
= note: cannot satisfy `<Self as Red>::R == _`
error[E0284]: type annotations needed: cannot satisfy `<Self as Red>::R == <Self as RedGreenBlue>::RGB`
--> src/lib.rs:28:5
|
28 | RedGreen<RG = <Self as RedGreenBlue>::RGB> + GreenBlue<GB = <Self as RedGreenBlue>::RGB>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Self as Red>::R == <Self as RedGreenBlue>::RGB`
|
note: required by a bound in `RedGreen`
--> src/lib.rs:19:25
|
19 | pub trait RedGreen: Red<R = <Self as RedGreen>::RG> + Blue<B = <Self as RedGreen>::RG> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `RedGreen`
error[E0284]: type annotations needed
--> src/lib.rs:30:5
|
30 | type RGB;
| ^^^^^^^^ cannot infer type
|
= note: cannot satisfy `<Self as Red>::R == _`