Index out of bounds? Not always! - A Rusty Surprise

Hi, recently I encountered a bit a odd behaviour, when indexing arrays with a static index.
I've described my journey in this blog post: Index out of bounds? Not always! - A Rusty Surprise | Serhii Potapov (greyblake)

I am also looking forward to what compiler experts think about it :slight_smile:

Thank you!

This is not an error, it's a warning ("lint" in Rust lingo). It's set to "deny" by default, so it turns into a compile error. But since it's just a warning, it's done on a best effort basis and doesn't catch every scenario of unconditional panic.

But I'm not quite sure why the warning doesn't trigger in the other scenarios.

2 Likes

In general, the problem of if a program will/will not panic is undecidable in a Turing complete language (equivalent to the classic and famous Halting problem).

Could the compiler possibly do better in specific cases like this? Maybe.