Skip to content

Commit 2b053e5

Browse files
committed
fn_to_numeric_cast_any: Do not warn cast to raw pointer
1 parent 227e43a commit 2b053e5

File tree

4 files changed

+5
-23
lines changed

4 files changed

+5
-23
lines changed

clippy_lints/src/casts/fn_to_numeric_cast_any.rs

-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ use rustc_middle::ty::{self, Ty};
88
use super::FN_TO_NUMERIC_CAST_ANY;
99

1010
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) {
11-
// We allow casts from any function type to any function type.
12-
match cast_to.kind() {
13-
ty::FnDef(..) | ty::FnPtr(..) => return,
14-
_ => { /* continue to checks */ },
15-
}
16-
1711
if let ty::FnDef(..) | ty::FnPtr(..) = cast_from.kind() {
1812
let mut applicability = Applicability::MaybeIncorrect;
1913
let from_snippet = snippet_with_applicability(cx, cast_expr.span, "..", &mut applicability);

clippy_lints/src/casts/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -846,9 +846,6 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
846846
cast_slice_from_raw_parts::check(cx, expr, cast_from_expr, cast_to, self.msrv);
847847
ptr_cast_constness::check(cx, expr, cast_from_expr, cast_from, cast_to, self.msrv);
848848
as_ptr_cast_mut::check(cx, expr, cast_from_expr, cast_to);
849-
fn_to_numeric_cast_any::check(cx, expr, cast_from_expr, cast_from, cast_to);
850-
fn_to_numeric_cast::check(cx, expr, cast_from_expr, cast_from, cast_to);
851-
fn_to_numeric_cast_with_truncation::check(cx, expr, cast_from_expr, cast_from, cast_to);
852849
zero_ptr::check(cx, expr, cast_from_expr, cast_to_hir);
853850

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

871871
as_underscore::check(cx, expr, cast_to_hir);

tests/ui/fn_to_numeric_cast_any.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn closure_to_fn_to_integer() {
8181

8282
fn fn_to_raw_ptr() {
8383
let _ = foo as *const ();
84-
//~^ fn_to_numeric_cast_any
84+
let _ = foo as *mut ();
8585
}
8686

8787
fn cast_fn_to_self() {

tests/ui/fn_to_numeric_cast_any.stderr

+1-13
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,4 @@ help: did you mean to invoke the function?
176176
LL | let _ = (clos as fn(u32) -> u32)() as usize;
177177
| ++
178178

179-
error: casting function pointer `foo` to `*const ()`
180-
--> tests/ui/fn_to_numeric_cast_any.rs:83:13
181-
|
182-
LL | let _ = foo as *const ();
183-
| ^^^^^^^^^^^^^^^^
184-
|
185-
help: did you mean to invoke the function?
186-
|
187-
LL | let _ = foo() as *const ();
188-
| ++
189-
190-
error: aborting due to 17 previous errors
191-
179+
error: aborting due to 16 previous errors

0 commit comments

Comments
 (0)