From How to understand the example of the Borrow trait in the Book?:
An important fact that isn’t explicitly mentioned in the book is this requirement from the
Borrowdocumentation :If you are implementing
Borrowand bothSelfandBorrowedimplementHash,Eq, and/orOrd, they must produce the same result.This isn’t enforced by the type system (so you can’t rely on it for memory safety), but it is a documented requirement for all implementers of the
Borrowtrait. This means that if you have aStringand an&stryou can hash both of them directly, without first converting them to have the same type.
Why are these invariants not enforced by the type system?