Skip to content

fn_to_numeric_cast_any: Do not warn cast to raw pointer #14109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 0 additions & 6 deletions clippy_lints/src/casts/fn_to_numeric_cast_any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ use rustc_middle::ty::{self, Ty};
use super::FN_TO_NUMERIC_CAST_ANY;

pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) {
// We allow casts from any function type to any function type.
match cast_to.kind() {
ty::FnDef(..) | ty::FnPtr(..) => return,
_ => { /* continue to checks */ },
}

if let ty::FnDef(..) | ty::FnPtr(..) = cast_from.kind() {
let mut applicability = Applicability::MaybeIncorrect;
let from_snippet = snippet_with_applicability(cx, cast_expr.span, "..", &mut applicability);
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/casts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,9 +846,6 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
cast_slice_from_raw_parts::check(cx, expr, cast_from_expr, cast_to, self.msrv);
ptr_cast_constness::check(cx, expr, cast_from_expr, cast_from, cast_to, self.msrv);
as_ptr_cast_mut::check(cx, expr, cast_from_expr, cast_to);
fn_to_numeric_cast_any::check(cx, expr, cast_from_expr, cast_from, cast_to);
fn_to_numeric_cast::check(cx, expr, cast_from_expr, cast_from, cast_to);
fn_to_numeric_cast_with_truncation::check(cx, expr, cast_from_expr, cast_from, cast_to);
zero_ptr::check(cx, expr, cast_from_expr, cast_to_hir);

if self.msrv.meets(cx, msrvs::MANUAL_DANGLING_PTR) {
Expand All @@ -866,6 +863,9 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
}
cast_lossless::check(cx, expr, cast_from_expr, cast_from, cast_to, cast_to_hir, self.msrv);
cast_enum_constructor::check(cx, expr, cast_from_expr, cast_from);
fn_to_numeric_cast_any::check(cx, expr, cast_from_expr, cast_from, cast_to);
fn_to_numeric_cast::check(cx, expr, cast_from_expr, cast_from, cast_to);
fn_to_numeric_cast_with_truncation::check(cx, expr, cast_from_expr, cast_from, cast_to);
}

as_underscore::check(cx, expr, cast_to_hir);
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/fn_to_numeric_cast_any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn closure_to_fn_to_integer() {

fn fn_to_raw_ptr() {
let _ = foo as *const ();
//~^ fn_to_numeric_cast_any
let _ = foo as *mut ();
}

fn cast_fn_to_self() {
Expand Down
13 changes: 1 addition & 12 deletions tests/ui/fn_to_numeric_cast_any.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,5 @@ help: did you mean to invoke the function?
LL | let _ = (clos as fn(u32) -> u32)() as usize;
| ++

error: casting function pointer `foo` to `*const ()`
--> tests/ui/fn_to_numeric_cast_any.rs:83:13
|
LL | let _ = foo as *const ();
| ^^^^^^^^^^^^^^^^
|
help: did you mean to invoke the function?
|
LL | let _ = foo() as *const ();
| ++

error: aborting due to 17 previous errors
error: aborting due to 16 previous errors

Loading