On Fri, Mar 7, 2025 at 11:58 AM Benno Lossin <benno.lossin@xxxxxxxxx> wrote: > > On Fri Mar 7, 2025 at 5:41 PM CET, Tamir Duberstein wrote: > > In Rust 1.51.0, Clippy introduced the `ignored_unit_patterns` lint [1]: > > You link to the `ptr_as_ptr` lint though, is this a typo? > > >> Though `as` casts between raw pointers are not terrible, > >> `pointer::cast` is safer because it cannot accidentally change the > >> pointer's mutability, nor cast the pointer to other types like `usize`. > > > > There are a few classes of changes required: > > - Modules generated by bindgen are marked > > `#[allow(clippy::ptr_as_ptr)]`. > > - Inferred casts (` as _`) are replaced with `.cast()`. > > - Ascribed casts (` as *... T`) are replaced with `.cast::<T>()`. > > - Multistep casts from references (` as *const _ as *const T`) are > > replaced with `let x: *const _ = &x;` and `.cast()` or `.cast::<T>()` > > according to the previous rules. The intermediate `let` binding is > > required because `(x as *const _).cast::<T>()` results in inference > > failure. > > - Native literal C strings are replaced with `c_str!().as_char_ptr()`. > > These all seem very nice, thanks! I think it would also be a good idea > to enable `ptr_cast_constness` [1], since those are the other kind of > `as` usage that we should be doing via `cast_mut`/`cast_const`. > > There are still some legitimate uses of `as` casts, when unsizing > values. I don't know if these two lints can trigger on those, it would > be nice if they don't. So those should continue to use `as`, but other > than that, there shouldn't be any `as` in our code :) > > [1]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_cast_constness > > (I will take a look at the patch itself a bit later) I'll go ahead and send v2 soon where this has become a 5 patch series.