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/main.rs:3:1
|
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?