Re: [PATCH v2 2/6] rust: types: avoid `as` casts
From: Tamir Duberstein
Date: Fri Nov 08 2024 - 07:23:07 EST
On Fri, Nov 8, 2024 at 6:35 AM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>
> On Mon, Nov 4, 2024 at 10:20 PM Tamir Duberstein <tamird@xxxxxxxxx> wrote:
> >
> > Replace `as` casts with `cast{,_const,_mut}` which are a bit safer.
> >
> > Signed-off-by: Tamir Duberstein <tamird@xxxxxxxxx>
>
> The compiler auto-converts from *mut to *const, so only cast_mut() is
> necessary. I think this will still compile if you get rid of all of
> the cast_const() calls.
I thought that wouldn't work because of type inference but it does - I
guess the compiler derefs *mut T to *const T before the cast() to
*const U.
Will change in v3, thanks.