This is a design choice. You want more flexibility, other people want code simpler to understand. Rust has chosen to tie their syntax with semantics and that’s one of the ways to “tame” operator overloading in programming languages.
Do you have a link to where this deliberate design choice was made? I'd like to read any rationale, because we have been trying to come up with semantics for PartialOrd
for a while now so that the is_sorted
RFC can make some progress, without much success. Any discussion that gave semantic meaning to PartialOrd
's operators could help us a lot there (last discussion about this is here).
Also (playground):
fn main() {
println!("{}", "1".to_string() + "2"); // prints: 12 instead of 3
}
looks more like concatenation than addition to me. So what does impl Add for T
mean? The trait is called Add
which implies addition, but in some cases it implements concatenation instead, and the trait documentation doesn't really state anything about the trait semantics.
So sure, tying operator overloading with semantics is a possible direction that a programming language might go, but doing so without concisely stating the semantic meaning (e.g. can I rely on associativity when using Add
to constrain a T
?) and then given them different meanings depending on the type, and giving some operators meanings and others no meaning, that would be a pretty weird design direction to choose if you ask me. So I am very skeptical that any of this was deliberate, but if it was, I'd like to know why it was decided to go this way.