1 use clippy_utils::diagnostics::span_lint_and_sugg;
2 use clippy_utils::source::snippet_with_applicability;
3 use rustc_errors::Applicability;
5 use rustc_lint::LateContext;
6 use rustc_middle::ty::{self, Ty};
8 use super::FN_TO_NUMERIC_CAST_ANY;
10 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 */ },
17 match cast_from.kind() {
18 ty::FnDef(..) | ty::FnPtr(_) => {
19 let mut applicability = Applicability::MaybeIncorrect;
20 let from_snippet = snippet_with_applicability(cx, cast_expr.span, "..", &mut applicability);
24 FN_TO_NUMERIC_CAST_ANY,
26 &format!("casting function pointer `{}` to `{}`", from_snippet, cast_to),
27 "did you mean to invoke the function?",
28 format!("{}() as {}", from_snippet, cast_to),