I guess I’ll have to go dig up the RFC discussion on this one; it should make for interesting reading.
2. This might (I haven't profiled it) introduce performance regressions in ways which should not happen.
3. Besides in some usages around `dyn` other usages of `as` get increasingly more alternatives. It's just a question of time until `as` (for int/float casts) is recommended to not be used at all, maybe even linted against.
4. Given precedence of many other programming languages people don't expect a "simple" float to int cast to be failable. (The new methods replacing `as` make the fallibility clear, as it's e.g. `u64::try_from(bigf64)`).
5. It's udef-ness is only detected/handled in llvm, _I don't know_ if llvm provides similar well integrated mechanisms for this as it does for integer overflows. If not that would be another problem.
So, instead of this being traditional UB, it was a combination of two separate issues:
- Rustc erroneously emitting code that exercised an LLVM UB case, and
- Imprecise Rust documentation around the exact behavior of float -> int ‘as’ casts
Because casting to floats is not UB in the Rust spec, it's UB in LLVM. That's the whole reason this was an issue in the first place.
Now, Rust could have chosen to define the behavior to panic, but so far it's been a hard and fast rule in Rust that as casts do not panic. You would have to have a much better reason to change that then "well, it was UB before" since (1) nobody wanted it to be UB before, and (2) the actual implementation never panicked (and people absolutely rely on the fact that casts don't panic in unsafe code).
Without knowing this case, I'd wager a guess: it's about performance. Panicking introduces a branch and side-effects which, again, affects negstively optimization potential and performance. The saturating cast affects performance too, but less. If some old code has a lot of number crunching containing these operations, a big performance regression would be nasty.
https://github.com/rust-lang/rust/issues/10184#issuecomment-...
I don't disagree that making more obvious errors into panics would be nice, but the performance implications are often quite unforgiving.