I almost knew that was going to be your reply.
That long-winded explanation is basically what anyone would sensibly expect (and that's no coincidence). The only thing I couldn't guess without reading the documentation if I were new to Rust is whatever NaN as integer
does. Everything else aims to produce the closest value in the target type (when converting between integers and floats-used-as-reals) or does what's the most hardware-efficient while still yielding a reasonable value (truncate or zero/sign-extend). See, this can be written down in 1 or 2 sentences.
The Rust documentation tries to be friendly, elaborate, and eloquent as a work of prose, but if you look at the content that really matters, it all just boils down to the high-level idea of "preserve bits if converting between ints, preserve values when converting to/from float, and both kinds of cast are on a best-effort basis". There might be a lot of words in the documentation, but that's not what the actual Kolmogorov complexity of its semantics is.
There's no expr as Trait
in Rust. You are probably thinking about Type as Trait
, which is in a completely different context (it's type-level, not value-level), so it can't be mistaken for value as Type
. By the same argument, it could be said that the for
keyword is ambiguous and must be abolished. Yet somehow hardly anyone is ever confused about $Trait for $Type
(in impl
definition context) having a different meaning from that of for $pattern in $value
(in statement context), exactly because they are in different contexts, and context matters a lot.
See, you didn't even complain about use crate::name as other_name
containing the as
keyword, even though it's a thing – you probably didn't even think about it, because it's conceptually so far from both other uses of the keyword that it cannot really be confused with either of them.
Oh, and finally, let me point out that this is a pretty useless strawman. The semantics of as
are compiler built-ins; it is exactly for this reason that everything a cast can do comes from a small, finite, closed set of possible operations. In contrast, general expressions bear no such restrictions. Even the innocent function call can do arbitrary (and arbitrarily bad) things. Would you also suggest that there shouldn't be functions in the language, because they are too confusing?