use std::ops::Add; pub trait Encoder { type Size: Add; fn foo(&self) -> Self::Size; } pub trait SubEncoder: Encoder { type ActualSize; fn bar(&self) -> Self::Size; } impl Encoder for T where T: SubEncoder, { type Size = ::ActualSize; //~^ ERROR: cannot add `::ActualSize` to `::ActualSize` fn foo(&self) -> Self::Size { self.bar() + self.bar() } } pub struct UnitEncoder; impl SubEncoder for UnitEncoder { type ActualSize = (); fn bar(&self) {} } pub fn fun(encoder: &R) { encoder.foo(); } fn main() { fun(&UnitEncoder {}); }