Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clippy_lints/src/casts/ptr_as_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/crashes/ice-12616.fixed
Original file line number Diff line number Diff line change
@@ -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::<()>();
}
7 changes: 7 additions & 0 deletions tests/ui/crashes/ice-12616.rs
Original file line number Diff line number Diff line change
@@ -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 ();
}
19 changes: 19 additions & 0 deletions tests/ui/crashes/ice-12616.stderr
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the duplicate diagnostic issue here is tracked over at #12379

--> 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