resolve code review comments

This commit is contained in:
John Arundel 2024-07-07 10:44:27 +01:00
parent 625091d236
commit f7050b0c78
6 changed files with 43 additions and 44 deletions

View File

@ -15,7 +15,7 @@ declare_clippy_lint! {
/// `MutexGuard`. /// `MutexGuard`.
/// ///
/// ### Why is this bad? /// ### Why is this bad?
/// The Mutex types found in [`std::sync`] and /// The Mutex types found in [`std::sync`][https://doc.rust-lang.org/stable/std/sync/] and
/// [`parking_lot`](https://docs.rs/parking_lot/latest/parking_lot/) are /// [`parking_lot`](https://docs.rs/parking_lot/latest/parking_lot/) are
/// not designed to operate in an async context across await points. /// not designed to operate in an async context across await points.
/// ///

View File

@ -244,9 +244,9 @@ declare_clippy_lint! {
/// ///
/// ### Why is this bad? /// ### Why is this bad?
/// Casting a function pointer to anything other than `usize`/`isize` is /// Casting a function pointer to anything other than `usize`/`isize` is
/// not portable across architectures. It either loses bits if the target /// not portable across architectures. If the target type is too small the
/// type is too small, or creates extra bits that waste space and bloat the /// address would be truncated, and target types larger than `usize` are
/// resulting binary. /// unnecessary.
/// ///
/// Casting to `isize` also doesn't make sense, since addresses are never /// Casting to `isize` also doesn't make sense, since addresses are never
/// signed. /// signed.
@ -373,7 +373,7 @@ declare_clippy_lint! {
declare_clippy_lint! { declare_clippy_lint! {
/// ### What it does /// ### What it does
/// Checks for `as` casts on a raw pointer that don't change its /// Checks for `as` casts between raw pointers that don't change their
/// mutability, namely `*const T` to `*const U` and `*mut T` to `*mut U`. /// mutability, namely `*const T` to `*const U` and `*mut T` to `*mut U`.
/// ///
/// ### Why is this bad? /// ### Why is this bad?
@ -398,12 +398,12 @@ declare_clippy_lint! {
#[clippy::version = "1.51.0"] #[clippy::version = "1.51.0"]
pub PTR_AS_PTR, pub PTR_AS_PTR,
pedantic, pedantic,
"casting using `as` on a raw pointer that doesn't change its mutability, where `pointer::cast` could take the place of `as`" "casting using `as` between raw pointers that doesn't change their constness, where `pointer::cast` could take the place of `as`"
} }
declare_clippy_lint! { declare_clippy_lint! {
/// ### What it does /// ### What it does
/// Checks for `as` casts on a raw pointer that change its constness, namely `*const T` to /// Checks for `as` casts between raw pointers that change their constness, namely `*const T` to
/// `*mut T` and `*mut T` to `*const T`. /// `*mut T` and `*mut T` to `*const T`.
/// ///
/// ### Why is this bad? /// ### Why is this bad?

View File

@ -92,7 +92,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: &Msrv) {
cx, cx,
PTR_AS_PTR, PTR_AS_PTR,
expr.span, expr.span,
"`as` casting between raw pointers without changing its mutability", "`as` casting between raw pointers without changing their constness",
help, help,
final_suggestion, final_suggestion,
app, app,

View File

@ -632,8 +632,7 @@ declare_clippy_lint! {
/// or `_.or_else(|x| Err(y))`. /// or `_.or_else(|x| Err(y))`.
/// ///
/// ### Why is this bad? /// ### Why is this bad?
/// This can be written more concisely as `_.map(|x| y)` or `_.map_err(|x| /// This can be written more concisely as `_.map(|x| y)` or `_.map_err(|x| y)`.
/// y)`.
/// ///
/// ### Example /// ### Example
/// ```no_run /// ```no_run

View File

@ -1,4 +1,4 @@
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/crashes/ice-12616.rs:6:5 --> tests/ui/crashes/ice-12616.rs:6:5
| |
LL | s() as *const (); LL | s() as *const ();

View File

@ -1,4 +1,4 @@
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:18:33 --> tests/ui/ptr_as_ptr.rs:18:33
| |
LL | *unsafe { Box::from_raw(Box::into_raw(Box::new(o)) as *mut super::issue_11278_a::T<String>) } LL | *unsafe { Box::from_raw(Box::into_raw(Box::new(o)) as *mut super::issue_11278_a::T<String>) }
@ -7,37 +7,37 @@ LL | *unsafe { Box::from_raw(Box::into_raw(Box::new(o)) as *mut super::i
= note: `-D clippy::ptr-as-ptr` implied by `-D warnings` = note: `-D clippy::ptr-as-ptr` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::ptr_as_ptr)]` = help: to override `-D warnings` add `#[allow(clippy::ptr_as_ptr)]`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:27:13 --> tests/ui/ptr_as_ptr.rs:27:13
| |
LL | let _ = ptr as *const i32; LL | let _ = ptr as *const i32;
| ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::<i32>()` | ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::<i32>()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:28:13 --> tests/ui/ptr_as_ptr.rs:28:13
| |
LL | let _ = mut_ptr as *mut i32; LL | let _ = mut_ptr as *mut i32;
| ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::<i32>()` | ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::<i32>()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:33:17 --> tests/ui/ptr_as_ptr.rs:33:17
| |
LL | let _ = *ptr_ptr as *const i32; LL | let _ = *ptr_ptr as *const i32;
| ^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `(*ptr_ptr).cast::<i32>()` | ^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `(*ptr_ptr).cast::<i32>()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:46:25 --> tests/ui/ptr_as_ptr.rs:46:25
| |
LL | let _: *const i32 = ptr as *const _; LL | let _: *const i32 = ptr as *const _;
| ^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast()` | ^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:47:23 --> tests/ui/ptr_as_ptr.rs:47:23
| |
LL | let _: *mut i32 = mut_ptr as _; LL | let _: *mut i32 = mut_ptr as _;
| ^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast()` | ^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:50:21 --> tests/ui/ptr_as_ptr.rs:50:21
| |
LL | let _ = inline!($ptr as *const i32); LL | let _ = inline!($ptr as *const i32);
@ -45,157 +45,157 @@ LL | let _ = inline!($ptr as *const i32);
| |
= note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info)
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:71:13 --> tests/ui/ptr_as_ptr.rs:71:13
| |
LL | let _ = ptr as *const i32; LL | let _ = ptr as *const i32;
| ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::<i32>()` | ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::<i32>()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:72:13 --> tests/ui/ptr_as_ptr.rs:72:13
| |
LL | let _ = mut_ptr as *mut i32; LL | let _ = mut_ptr as *mut i32;
| ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::<i32>()` | ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::<i32>()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:79:9 --> tests/ui/ptr_as_ptr.rs:79:9
| |
LL | ptr::null_mut() as *mut u32 LL | ptr::null_mut() as *mut u32
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut::<u32>()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut::<u32>()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:83:9 --> tests/ui/ptr_as_ptr.rs:83:9
| |
LL | std::ptr::null_mut() as *mut u32 LL | std::ptr::null_mut() as *mut u32
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null_mut::<u32>()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null_mut::<u32>()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:88:9 --> tests/ui/ptr_as_ptr.rs:88:9
| |
LL | ptr::null_mut() as *mut u32 LL | ptr::null_mut() as *mut u32
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut::<u32>()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut::<u32>()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:92:9 --> tests/ui/ptr_as_ptr.rs:92:9
| |
LL | core::ptr::null_mut() as *mut u32 LL | core::ptr::null_mut() as *mut u32
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null_mut::<u32>()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null_mut::<u32>()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:97:9 --> tests/ui/ptr_as_ptr.rs:97:9
| |
LL | ptr::null() as *const u32 LL | ptr::null() as *const u32
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null::<u32>()` | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null::<u32>()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:101:9 --> tests/ui/ptr_as_ptr.rs:101:9
| |
LL | std::ptr::null() as *const u32 LL | std::ptr::null() as *const u32
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null::<u32>()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null::<u32>()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:106:9 --> tests/ui/ptr_as_ptr.rs:106:9
| |
LL | ptr::null() as *const u32 LL | ptr::null() as *const u32
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null::<u32>()` | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null::<u32>()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:110:9 --> tests/ui/ptr_as_ptr.rs:110:9
| |
LL | core::ptr::null() as *const u32 LL | core::ptr::null() as *const u32
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null::<u32>()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null::<u32>()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:117:9 --> tests/ui/ptr_as_ptr.rs:117:9
| |
LL | ptr::null_mut() as *mut _ LL | ptr::null_mut() as *mut _
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()` | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:121:9 --> tests/ui/ptr_as_ptr.rs:121:9
| |
LL | std::ptr::null_mut() as *mut _ LL | std::ptr::null_mut() as *mut _
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null_mut()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null_mut()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:126:9 --> tests/ui/ptr_as_ptr.rs:126:9
| |
LL | ptr::null_mut() as *mut _ LL | ptr::null_mut() as *mut _
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()` | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:130:9 --> tests/ui/ptr_as_ptr.rs:130:9
| |
LL | core::ptr::null_mut() as *mut _ LL | core::ptr::null_mut() as *mut _
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null_mut()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null_mut()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:135:9 --> tests/ui/ptr_as_ptr.rs:135:9
| |
LL | ptr::null() as *const _ LL | ptr::null() as *const _
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()` | ^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:139:9 --> tests/ui/ptr_as_ptr.rs:139:9
| |
LL | std::ptr::null() as *const _ LL | std::ptr::null() as *const _
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:144:9 --> tests/ui/ptr_as_ptr.rs:144:9
| |
LL | ptr::null() as *const _ LL | ptr::null() as *const _
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()` | ^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:148:9 --> tests/ui/ptr_as_ptr.rs:148:9
| |
LL | core::ptr::null() as *const _ LL | core::ptr::null() as *const _
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:155:9 --> tests/ui/ptr_as_ptr.rs:155:9
| |
LL | ptr::null_mut() as _ LL | ptr::null_mut() as _
| ^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()` | ^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:159:9 --> tests/ui/ptr_as_ptr.rs:159:9
| |
LL | std::ptr::null_mut() as _ LL | std::ptr::null_mut() as _
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null_mut()` | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null_mut()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:164:9 --> tests/ui/ptr_as_ptr.rs:164:9
| |
LL | ptr::null_mut() as _ LL | ptr::null_mut() as _
| ^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()` | ^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:168:9 --> tests/ui/ptr_as_ptr.rs:168:9
| |
LL | core::ptr::null_mut() as _ LL | core::ptr::null_mut() as _
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null_mut()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null_mut()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:173:9 --> tests/ui/ptr_as_ptr.rs:173:9
| |
LL | ptr::null() as _ LL | ptr::null() as _
| ^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()` | ^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:177:9 --> tests/ui/ptr_as_ptr.rs:177:9
| |
LL | std::ptr::null() as _ LL | std::ptr::null() as _
| ^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null()` | ^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:182:9 --> tests/ui/ptr_as_ptr.rs:182:9
| |
LL | ptr::null() as _ LL | ptr::null() as _
| ^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()` | ^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()`
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing their constness
--> tests/ui/ptr_as_ptr.rs:186:9 --> tests/ui/ptr_as_ptr.rs:186:9
| |
LL | core::ptr::null() as _ LL | core::ptr::null() as _