-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggest .cast()
instead of as
for pointer casts
#8017
Labels
A-lint
Area: New lints
Comments
taiki-e
added a commit
to rust-lang/futures-rs
that referenced
this issue
Jan 12, 2022
taiki-e
added a commit
to rust-lang/futures-rs
that referenced
this issue
Jan 12, 2022
taiki-e
added a commit
to rust-lang/futures-rs
that referenced
this issue
Jan 12, 2022
taiki-e
added a commit
to rust-lang/futures-rs
that referenced
this issue
Feb 6, 2022
taiki-e
added a commit
to rust-lang/futures-rs
that referenced
this issue
Feb 6, 2022
taiki-e
added a commit
to crossbeam-rs/crossbeam
that referenced
this issue
Jul 22, 2022
taiki-e
added a commit
to crossbeam-rs/crossbeam
that referenced
this issue
Jul 22, 2022
Does this seem implemented as clippy::ptr_as_ptr? |
Does ptr_as_ptr support the new |
This is now covered by |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What it does
Suggests using the more-scoped
cast
methodshttps://doc.rust-lang.org/std/primitive.pointer.html#method.cast
https://doc.rust-lang.org/std/primitive.pointer.html#method.cast-1
for pointer casting instead of the more-general
as
.Categories (optional)
(One could argue that this is more
pedantic
, as that's what https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless is. But I think that pointer casts are generally aroundunsafe
code, so the pedantry is more generally appropriate.)This helps avoid mistakes where the
as
cast is accidentally converting between*const _
and*mut _
, for example. For pointers it's often tempting to slap onas _
to make something work, but that's a very broad conversion.(This is not applicable for
*const T
<->*mut T
casts, which this lint should not warn about.)Drawbacks
None.
Example
From https://users.rust-lang.org/t/converting-between-unsized-transparent-types-safely-in-place/67680/19?u=scottmcm
Could be written as:
The text was updated successfully, but these errors were encountered: