avoid an ICE in ptr_as_ptr when getting the def_id of a local

This commit is contained in:
y21 2024-04-02 15:04:25 +02:00
parent 2b30a5924e
commit e575f05a8b
4 changed files with 34 additions and 1 deletions

View file

@ -0,0 +1,7 @@
#![warn(clippy::ptr_as_ptr)]
#![allow(clippy::unnecessary_operation, clippy::unnecessary_cast)]
fn main() {
let s = std::ptr::null::<()>;
s().cast::<()>();
}

View file

@ -0,0 +1,7 @@
#![warn(clippy::ptr_as_ptr)]
#![allow(clippy::unnecessary_operation, clippy::unnecessary_cast)]
fn main() {
let s = std::ptr::null::<()>;
s() as *const ();
}

View file

@ -0,0 +1,19 @@
error: `as` casting between raw pointers without changing its mutability
--> tests/ui/crashes/ice-12616.rs:6:5
|
LL | s() as *const ();
| ^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `s().cast::<()>()`
|
= note: `-D clippy::ptr-as-ptr` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::ptr_as_ptr)]`
error: `as` casting between raw pointers without changing its mutability
--> 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