diff --git a/clippy_lints/src/casts/ptr_as_ptr.rs b/clippy_lints/src/casts/ptr_as_ptr.rs index 35e36e9ef3f5..16de93136854 100644 --- a/clippy_lints/src/casts/ptr_as_ptr.rs +++ b/clippy_lints/src/casts/ptr_as_ptr.rs @@ -62,8 +62,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: &Msrv) { // we omit following `cast`: let omit_cast = if let ExprKind::Call(func, []) = cast_expr.kind && let ExprKind::Path(ref qpath @ QPath::Resolved(None, path)) = func.kind + && let Some(method_defid) = path.res.opt_def_id() { - let method_defid = path.res.def_id(); if cx.tcx.is_diagnostic_item(sym::ptr_null, method_defid) { OmitFollowedCastReason::Null(qpath) } else if cx.tcx.is_diagnostic_item(sym::ptr_null_mut, method_defid) { diff --git a/tests/ui/crashes/ice-12616.fixed b/tests/ui/crashes/ice-12616.fixed new file mode 100644 index 000000000000..a5a5b3d1e78e --- /dev/null +++ b/tests/ui/crashes/ice-12616.fixed @@ -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::<()>(); +} diff --git a/tests/ui/crashes/ice-12616.rs b/tests/ui/crashes/ice-12616.rs new file mode 100644 index 000000000000..6ee9a5ec08fe --- /dev/null +++ b/tests/ui/crashes/ice-12616.rs @@ -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 (); +} diff --git a/tests/ui/crashes/ice-12616.stderr b/tests/ui/crashes/ice-12616.stderr new file mode 100644 index 000000000000..ef573f55cf36 --- /dev/null +++ b/tests/ui/crashes/ice-12616.stderr @@ -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 +