extern crate ambassador; use ambassador::{delegatable_trait, Delegate}; use std::any::type_name; #[delegatable_trait] pub trait Taxonomy { type Res; } pub struct Cat; pub struct Dog; pub struct Alligator; pub struct Class; pub struct Mammal; pub struct Reptile; pub struct Kingdom; pub struct Animal; pub trait Base {} impl Base for Cat {} impl Taxonomy for Cat { type Res = Mammal; } impl Base for Dog {} impl Taxonomy for Dog { type Res = Mammal; } impl Base for Alligator {} impl Taxonomy for Alligator { type Res = Reptile; } impl Taxonomy for Mammal { type Res = Animal; } impl Taxonomy for Reptile { type Res = Animal; } impl> Taxonomy for E where >::Res: Taxonomy, { type Res = <>::Res as Taxonomy>::Res; } #[derive(Delegate)] #[delegate(Taxonomy, generics = "X")] pub enum Either { A(A), B(B), } pub fn main() { assert_eq!( type_name::< as Taxonomy>::Res>(), //~^ ERROR type mismatch resolving `>::Res == Reptile` type_name::() ); }