Trait bound doesn't imply itself?


I have the following code:

trait Foo<'a> where Self: 'a + Sized, &'a Self: std::ops::Add<&'a Self, Output = Self> {}

fn foo<'a, T: Foo<'a>>(t: T) -> T { t }

When I try compiling this program, I get the following error:

error[E0277]: the trait bound `&'a T: std::ops::Add` is not satisfied
 --> src/
3 | fn foo<'a, T: Foo<'a>>(t: T) -> T { t }
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `&'a T + &'a T`
  = help: the trait `std::ops::Add` is not implemented for `&'a T`
  = help: consider adding a `where &'a T: std::ops::Add` bound
  = note: required by `Foo`

I’m surprised by this because I would expect the T: Foo<'a> bound to imply &'a T: Add given that it’s in the definition of Foo. What am I getting wrong here?


I think this may get fixed with As it stands, you’re adding a bound on a different type - &Self - and that needs to be repeated today.


OK thanks!


This bug is probably relevant:


Oh good call; thanks!