r/ProgrammingLanguages • u/jamiiecb • Apr 10 '26
Borrow-checking surprises
https://www.scattered-thoughts.net/writing/borrow-checking-surprises
52
Upvotes
r/ProgrammingLanguages • u/jamiiecb • Apr 10 '26
View all comments
Show parent comment
1
u/fdwr Apr 16 '26 edited Apr 16 '26
The one decision that really makes me go "what were you thinking..." is that in basically every programming language, something akin to the following is valid:
Both
xandyare valid, and bothsandtare valid.In Rust though, the following may or may not be valid... 🎲
...depending on what type
ais. Ifawas assigned 42, then both andaandbare valid, but if it came fromlet a = String::from("hello"), and thenabecomes invalid afterb = a🙃. What other language abuses the=operator to mean something that violates this principle? If you want to repurpose=for something else like a stealing operation, then give it a less confusing distinct syntax, like saylet b <- awhich clearly indicates to the reader thatahas been stolen byb. (now someone will feel compelled to defend this and say it's a feature, not a design faux pas 🙄)