Why is the Eq trait not unsafe?
Stronger question, why aren't any of the PartialEq, Eq, PartialOrd and Ord traits (I would call them PEPO) unsafe?
From the Rust Nomicon:
On trait declarations, unsafe means that implementors of the trait must check the trait documentation to ensure their implementation maintains the contracts the trait requires.
The PEPO traits have requirements which have to be upheld by implementors. Thus it would be natural for them to be unsafe, this is even suggested in the same chapter of the Nomicon. When the traits aren't marked as unsafe but have requirements unsafe code must assume the trait contracts don't always hold. I can also easily imagine a safe function implicitly relying on the reflexivity of Eq for example and thus behaving differently than it should, breaking it's own safe invariants.
The reason behind not marking PEPO traits as unsafe is explained in the same chapter of the Nomicon:
The decision of whether to mark a trait unsafe is an API design choice. A safe trait is easier to implement, but any unsafe code that relies on it must defend against incorrect behavior. Marking a trait unsafe shifts this responsibility to the implementor. Rust has traditionally avoided marking traits unsafe because it makes Unsafe Rust pervasive, which isn't desirable.
This confuses me. How would marking the PEPO traits as unsafe make them harder to implement, when the trait contracts would be exactly the same and also, don't the benefits of marking the PEPO traits as unsafe outweigh the drawbacks? I would be glad to hear your opinions.