There is already a way to specify any assumption:
if !condition {
unsafe { core::hint::unreachable_unchecked() };
}
The assert-unchecked
crate wraps it into a macro assert_unchecked!
.
So you can already write this as:
if a & b == 0 {
a | b
} else {
unsafe { unreachable_unchecked() }
}
Similarly, you can already write:
unsafe { a.checked_mul(b).unwrap_unchecked() }
so it's strange to me that additional functions like unchecked_mul
are being added to u32
for this specific operation.
The rationale for adding unchecked_mul
is that the above doesn't optimize equally well, but wouldn't a better solution be to improve the optimizer rather than add redundant functions?