4 ms·
The blog post does not support the assertion that unreachable UB which is not executed is a problem. It starts by saying > The Rust compiler has a few assumpti
by nickitolas 4y ago
The blog post does not support the assertion that unreachable UB which is not executed is a problem. It starts by saying
> The Rust compiler has a few assumptions that it makes about the behavior of all code. Violations of those assumptions are referred to as Undefined Behavior.
Then it says
> In other words, even just constructing, for example, an invalid bool, is Undefined Behavior—no matter whether that bool is ever actually “used” by the program.
The blog post is talking about how just creating an invalid/trap/niche representation for a value is UB. The act of creating the value is the UB here, not the usage. So, in this case the UB is most definetely reachable and executing (The act of creating the invalid value).