Adding a constraint to a base trait breaks a derived trait?!
I've been using Rust for years and I've encountered a new problem that sure feels like an unnecessary language limitation, where adding a constraint to a trait breaks another trait that's derived from it, for example:
trait AddToI32
where
Self: Sized,
Self: Add<i32, Output = Self>,
i32: Add<Self, Output = Self>, // this line causes an error
{}
trait Subtrait
where
Self: AddToI32,
i32: Add<Self, Output = Self>, // this line makes the error go away
{}
My thinking is that the offending trait bound in AddToI32 should result in the bound i32: Add<Self, Output=Self> being propagated to Subtrait, but that's not what happens. I can kind of see the logic that adding a constraint with Self on the left can't magically add a constraint with i32 on the left, but it would be so convenient!
Can anyone offer insight into what I'm trying to do should or should not work?
Playground link here.
Posted Apr 3, 2026, 4:48 PM UTC
1110