On Tue, Nov 25, 2025 at 01:09:42AM +0000, Matthew Wilcox wrote:
> so the Rust language people have clearly decided that this is too
> complicated for your average programmer to figure out, and you need
> explicit casts to make it work.

Yup, and this is correct: "intent" becomes explicit. Doing implicit
extension, narrowing, and truncation is just a mess. As part of the
Overflow Behavior Type work, Justin has also been looking at something
that would allow a typedef to not be allowed to be mixed with other
types (i.e. to do so requires explicit casts). For example:

__strong typedef unsigned short only_u16;
...
only_u16 foo;
int bar = ...;
...
foo = bar; // Build failure: mismatched types
foo = (u16)bar; // okay, explicit truncation

-Kees

-- 
Kees Cook

Reply via email to