r/rust • u/rustacean1337 • Nov 17 '22
What are Rust’s biggest weaknesses?
What would you say are Rust’s biggest weaknesses right now? And are they things that can be fixed in future versions do you think or is it something that could only be fixed by introducing a breaking change? Let’s say if you could create a Rust 2.0 and therefore not worry about backwards compatibility what would you do different.
220
Upvotes
View all comments
Show parent comment
1
u/CocktailPerson Nov 19 '22 edited Nov 19 '22
It may not be a source of bugs, but it can certainly hide them. For example:
This doesn't contain any unsafe conversions. But it contains a logic error that will be caught by strict typing. That's kind of the fundamental value proposition of strict typing in general: type errors are a pretty good proxy for logic errors.
There are other issues, too. Implicit type conversions could silently create optimization issues, as https://godbolt.org/z/YdM1YxeM1 shows. If you look at the generated code for each function, you'll see they're basically doing the same thing, except where
add_64has to doadd_i32only doesThose extra three lines before
movdquare vectorized integer promotions, and they're pretty expensive. The first one also has to maintain a loop counter inrax, where the second one can just unroll the whole loop. If type conversions were implicit, I'm not sure you'd be able to see this was happening at all. It can get even worse when you're dealing with a few layers of indirection, and in my line of work, this (sub-)optimization is definitely a bug.