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.
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.