1 use super::CAST_NAN_TO_INT;
3 use clippy_utils::consts::{constant, Constant};
4 use clippy_utils::diagnostics::span_lint_and_note;
6 use rustc_lint::LateContext;
7 use rustc_middle::ty::Ty;
9 pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, from_ty: Ty<'_>, to_ty: Ty<'_>) {
10 if from_ty.is_floating_point() && to_ty.is_integral() && is_known_nan(cx, cast_expr) {
15 &format!("casting a known NaN to {to_ty}"),
17 "this always evaluates to 0",
22 fn is_known_nan(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
23 match constant(cx, cx.typeck_results(), e) {
24 Some((Constant::F64(n), _)) => n.is_nan(),
25 Some((Constant::F32(n), _)) => n.is_nan(),