Hacker News new | past | comments | ask | show | jobs | submit login

It's a common misconception due in large part to Rust's marketing.

Claim: Rust enables you to eliminate many classes of bugs at compile-time. (https://www.rust-lang.org, "Why Rust?", "Reliability")

Reality: Rust enables you to eliminate an extremely limited class of bugs at compile time, and also inserts if statements into your program to detect some other classes of bugs at runtime and crash cleanly.




If you count optimizing your ill-formed function into an inlined panic [1] as "bug eliminated at compile-time", then it may be true!

https://godbolt.org/z/M7Gr3TazE


While it would obviously be nice to error at compile time, the docs of the slice type clearly say the code mudt panic in this case. Depending on the context, [T; 3] may be better




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: