Extend unnecessary_cast lint to detect unnecessary ptr::cast() calls#16680
Extend unnecessary_cast lint to detect unnecessary ptr::cast() calls#16680lapla-cogito wants to merge 1 commit intorust-lang:masterfrom
unnecessary_cast lint to detect unnecessary ptr::cast() calls#16680Conversation
|
rustbot has assigned @samueltardieu. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Lintcheck changes for 854aa39
This comment will be updated if you push new changes |
1ea877b to
32235e9
Compare
This comment has been minimized.
This comment has been minimized.
32235e9 to
632e3e5
Compare
This comment has been minimized.
This comment has been minimized.
| //@[edition2018] check-pass | ||
| #![warn(clippy::manual_c_str_literals)] | ||
| #![allow(clippy::no_effect)] | ||
| #![allow(clippy::no_effect, clippy::unnecessary_cast)] |
There was a problem hiding this comment.
Initially, I considered using #[expect(clippy::unnecessary_cast)] for let _: *const _ = b"foo\0".as_ptr().cast::<i8>();, but this appears to only occur in edition 2021 (where edition 2018 triggers an unfulfilled lint). Therefore, I'm using #[allow] instead.
632e3e5 to
bc9f5a3
Compare
| && let ty::RawPtr(to_pointee_ty, to_mutbl) = result_ty.kind() | ||
| && from_mutbl == to_mutbl | ||
| && from_pointee_ty == to_pointee_ty | ||
| && !from_pointee_ty.has_erased_regions() |
There was a problem hiding this comment.
I added this based on lintcheck results from the first version. The first tokio-util case intentionally modified the lifetimes, which I think is a FP.
bc9f5a3 to
430ccc7
Compare
This comment has been minimized.
This comment has been minimized.
430ccc7 to
54334d8
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
54334d8 to
854aa39
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
friendly ping @samueltardieu |
close #15624
Casts to type aliases, cfg-dependent types, and explicit wildcards (
ptr.cast::<_>()) are intentionally excluded to stay consistent with the existingas-cast behavior.changelog: [
unnecessary_cast]: also lint unnecessaryptr::cast()calls