diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2025-08-22 17:19:44 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-22 17:19:44 +0000 |
| commit | 8a8caeb99c8f4f5460520f411e910e58764ebc09 (patch) | |
| tree | 4a54cbbc45af345f2c9436d0ae21c3c2376dff8d /tests/ui | |
| parent | 7997f33b5d59a6c49eaa1554ab2ad7c688b3eb5d (diff) | |
| parent | 443860d1ae4310e12188e05278fc34fd01ace1c6 (diff) | |
| download | rust-8a8caeb99c8f4f5460520f411e910e58764ebc09.tar.gz rust-8a8caeb99c8f4f5460520f411e910e58764ebc09.zip | |
ptr_as_ptr: fix incorrect suggestion with `pointer::cast` and macros (#15514)
Fixes https://github.com/rust-lang/rust-clippy/issues/15232 changelog: [`ptr_as_ptr`]: fix incorrect suggestion with `pointer::cast` and macros
Diffstat (limited to 'tests/ui')
| -rw-r--r-- | tests/ui/ptr_as_ptr.fixed | 6 | ||||
| -rw-r--r-- | tests/ui/ptr_as_ptr.rs | 6 | ||||
| -rw-r--r-- | tests/ui/ptr_as_ptr.stderr | 8 |
3 files changed, 19 insertions, 1 deletions
diff --git a/tests/ui/ptr_as_ptr.fixed b/tests/ui/ptr_as_ptr.fixed index 78e1ceb480a..4457878b6fa 100644 --- a/tests/ui/ptr_as_ptr.fixed +++ b/tests/ui/ptr_as_ptr.fixed @@ -229,3 +229,9 @@ fn issue15283() { //~^ ptr_as_ptr } } + +fn issue15232() { + let mut b = Box::new(0i32); + let _ptr = std::ptr::addr_of_mut!(*b).cast::<()>(); + //~^ ptr_as_ptr +} diff --git a/tests/ui/ptr_as_ptr.rs b/tests/ui/ptr_as_ptr.rs index 70732cf0a6c..9124fc912d2 100644 --- a/tests/ui/ptr_as_ptr.rs +++ b/tests/ui/ptr_as_ptr.rs @@ -229,3 +229,9 @@ fn issue15283() { //~^ ptr_as_ptr } } + +fn issue15232() { + let mut b = Box::new(0i32); + let _ptr = std::ptr::addr_of_mut!(*b) as *mut (); + //~^ ptr_as_ptr +} diff --git a/tests/ui/ptr_as_ptr.stderr b/tests/ui/ptr_as_ptr.stderr index c0a2a4b6d20..af21c1e35f5 100644 --- a/tests/ui/ptr_as_ptr.stderr +++ b/tests/ui/ptr_as_ptr.stderr @@ -199,5 +199,11 @@ error: `as` casting between raw pointers without changing their constness LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>() as *const u8); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null::<u8>()` -error: aborting due to 33 previous errors +error: `as` casting between raw pointers without changing their constness + --> tests/ui/ptr_as_ptr.rs:235:16 + | +LL | let _ptr = std::ptr::addr_of_mut!(*b) as *mut (); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `std::ptr::addr_of_mut!(*b).cast::<()>()` + +error: aborting due to 34 previous errors |
