[ptr_as_ptr]: Fix duplicate errors

This commit is contained in:
Luv-Ray 2024-04-13 14:35:44 +08:00 committed by blyxyas
parent 7063e3435c
commit da0ae33c15
5 changed files with 34 additions and 45 deletions

View file

@ -757,7 +757,6 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
if in_external_macro(cx.sess(), expr.span) { if in_external_macro(cx.sess(), expr.span) {
return; return;
} }
ptr_as_ptr::check(cx, expr, &self.msrv);
if let ExprKind::Cast(cast_expr, cast_to_hir) = expr.kind { if let ExprKind::Cast(cast_expr, cast_to_hir) = expr.kind {
if is_hir_ty_cfg_dependant(cx, cast_to_hir) { if is_hir_ty_cfg_dependant(cx, cast_to_hir) {

View file

@ -7,13 +7,5 @@ LL | s() as *const ();
= 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: aborting due to 1 previous error
--> tests/ui/crashes/ice-12616.rs:6:5
|
LL | s() as *const ();
| ^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `s().cast::<()>()`
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: aborting due to 2 previous errors

View file

@ -1,5 +1,4 @@
//@aux-build:proc_macros.rs //@aux-build:proc_macros.rs
//@compile-flags: -Zdeduplicate-diagnostics=yes
#![warn(clippy::ptr_as_ptr)] #![warn(clippy::ptr_as_ptr)]

View file

@ -1,5 +1,4 @@
//@aux-build:proc_macros.rs //@aux-build:proc_macros.rs
//@compile-flags: -Zdeduplicate-diagnostics=yes
#![warn(clippy::ptr_as_ptr)] #![warn(clippy::ptr_as_ptr)]

View file

@ -1,5 +1,5 @@
error: `as` casting between raw pointers without changing its mutability error: `as` casting between raw pointers without changing its mutability
--> tests/ui/ptr_as_ptr.rs:19: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>) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `Box::into_raw(Box::new(o)).cast::<super::issue_11278_a::T<String>>()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `Box::into_raw(Box::new(o)).cast::<super::issue_11278_a::T<String>>()`
@ -8,37 +8,37 @@ LL | *unsafe { Box::from_raw(Box::into_raw(Box::new(o)) as *mut super::i
= 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 its mutability
--> tests/ui/ptr_as_ptr.rs:28: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 its mutability
--> tests/ui/ptr_as_ptr.rs:29: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 its mutability
--> tests/ui/ptr_as_ptr.rs:34: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 its mutability
--> tests/ui/ptr_as_ptr.rs:47: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 its mutability
--> tests/ui/ptr_as_ptr.rs:48: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 its mutability
--> tests/ui/ptr_as_ptr.rs:51:21 --> tests/ui/ptr_as_ptr.rs:50:21
| |
LL | let _ = inline!($ptr as *const i32); LL | let _ = inline!($ptr as *const i32);
| ^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `$ptr.cast::<i32>()` | ^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `$ptr.cast::<i32>()`
@ -46,157 +46,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 its mutability
--> tests/ui/ptr_as_ptr.rs:72: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 its mutability
--> tests/ui/ptr_as_ptr.rs:73: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 its mutability
--> tests/ui/ptr_as_ptr.rs:80: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 its mutability
--> tests/ui/ptr_as_ptr.rs:84: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 its mutability
--> tests/ui/ptr_as_ptr.rs:89: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 its mutability
--> tests/ui/ptr_as_ptr.rs:93: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 its mutability
--> tests/ui/ptr_as_ptr.rs:98: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 its mutability
--> tests/ui/ptr_as_ptr.rs:102: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 its mutability
--> tests/ui/ptr_as_ptr.rs:107: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 its mutability
--> tests/ui/ptr_as_ptr.rs:111: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 its mutability
--> tests/ui/ptr_as_ptr.rs:118: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 its mutability
--> tests/ui/ptr_as_ptr.rs:122: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 its mutability
--> tests/ui/ptr_as_ptr.rs:127: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 its mutability
--> tests/ui/ptr_as_ptr.rs:131: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 its mutability
--> tests/ui/ptr_as_ptr.rs:136: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 its mutability
--> tests/ui/ptr_as_ptr.rs:140: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 its mutability
--> tests/ui/ptr_as_ptr.rs:145: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 its mutability
--> tests/ui/ptr_as_ptr.rs:149: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 its mutability
--> tests/ui/ptr_as_ptr.rs:156: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 its mutability
--> tests/ui/ptr_as_ptr.rs:160: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 its mutability
--> tests/ui/ptr_as_ptr.rs:165: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 its mutability
--> tests/ui/ptr_as_ptr.rs:169: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 its mutability
--> tests/ui/ptr_as_ptr.rs:174: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 its mutability
--> tests/ui/ptr_as_ptr.rs:178: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 its mutability
--> tests/ui/ptr_as_ptr.rs:183: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 its mutability
--> tests/ui/ptr_as_ptr.rs:187:9 --> tests/ui/ptr_as_ptr.rs:186:9
| |
LL | core::ptr::null() as _ LL | core::ptr::null() as _
| ^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null()` | ^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null()`