On 12/2/25 6:14 PM, Joel Fernandes wrote: >> On Dec 2, 2025, at 7:46 PM, John Hubbard <[email protected]> wrote: ... >>> suspect that in both cases, the compiler cannot tell that each chunk is >>> always 4 bytes and >>> try_into() will never panic. In my case, word[3] always exists and will >>> never panic either. So I'm >>> guess that the compiler will still emit code to check for panic. I don't >>> know. >>> >> >> Good question. Maybe someone with Rust experience can enlighten us on >> that one. > > If the optimizer could not eliminate the dead code, IMO that is a bug, pretty > much like how we rely on dead code elimination optimization for build_assert. > > It is worth compiling and checking but I am almost certain the dead code for > an unreachable case (in this case, panicking, will be eliminated). >
Well yes, but the question remains: is the compiler able to even identify this as dead code? Because it depends on the early -EINVAL return, in order to be correct. Is rustc able to figure out that kind of situation? thanks, -- John Hubbard
