3 ms·
I think namespace qualification syntax and trait bounds make it more confusing `<P::Neg>::Output: 'a` gives me eye cancer and my intuition is if `P: Neg + 'a`
by iopq 12y ago
I think namespace qualification syntax and trait bounds make it more confusing
`<P::Neg>::Output: 'a` gives me eye cancer and my intuition is if `P: Neg + 'a` then `P::Output: 'a` is implied (why would it not have that bound if P does?)
the Neg trait's Output IS Self (as Neg)! Why is the bound not transitive?
- pcwalton 12y ago> `<P::Neg>::Output: 'a` gives me eye cancer and my intuition is if `P: Neg + 'a` then `P::Output: 'a` is implied (why would it not have that bound if P does?) What if the output of the unary minus method was say, a constant 'static? This is a reasonable thing for a function to want to do in general. (Probably not for Neg in particular, but obviously we don't want to add special cases in the inference for specific traits.) The function needs to know about it because you can do many more things with a 'static than a 'a (as 'static references can never become dangling).
- iopq 12y agoBut it's not, the Output is Self not Self + 'static
- pcwalton 12y agoI think you're misunderstanding what Self means in the definition of Neg. The Self is only there so that it is clear which type's "Output" is being referred to. It doesn't establish any type/trait/lifetime relationship between the type of the receiver and the output type. It would be perfectly possible to implement Neg with a 'static output lifetime.
- iopq 12y agoYeah, I got it, people on IRC helped me understand that it's not casting it as `Neg`, it's casting the type as `Neg` for namespacing purposes