I can't tell if I didn't understand an important detail about Rust traits or the system is badly underdesigned, but I keep bumping into situations where the most general correct implementation of an std trait on a container clashes with one of the std implementations, and I would need a very obvious negative statement to make them mutually exclusive (for example that T in MyPtr<T> can never implement Borrow<MyPtr<T>>)

  • 2
    rust survey dropped and the most desired problem users surveyed wanted fixed was traits

    so maybe (for I did not understand šŸ˜)
  • 0
    Actually, I think Borrow targets should be marked. Obviously that ship had sailed with Rust 1.0, but it would fix a ton of problems like this. For one, all statements of the type

    impl<T: Borrow<U>, U: Borrowed> Borrow<U> for MyPtr<T>

    would become valid because it can be statically known that MyPtr doesn't implement Borrowed because it doesn't make sense to borrow up to but not through a smart pointer.
  • 0
    I guess this can become a problem with inference because the argument of a trait is technically an inference target and this alternative version of Borrow would have implementations for potentially tens of arguments at a time so it might be very very slow.
Add Comment