1 use super::TRANSMUTE_NUM_TO_BYTES;
2 use clippy_utils::diagnostics::span_lint_and_then;
3 use clippy_utils::sugg;
4 use rustc_errors::Applicability;
6 use rustc_lint::LateContext;
7 use rustc_middle::ty::{self, Ty, UintTy};
9 /// Checks for `transmute_int_to_float` lint.
10 /// Returns `true` if it's triggered, otherwise returns `false`.
11 pub(super) fn check<'tcx>(
12 cx: &LateContext<'tcx>,
16 args: &'tcx [Expr<'_>],
19 match (&from_ty.kind(), &to_ty.kind()) {
20 (ty::Int(_) | ty::Uint(_) | ty::Float(_), ty::Array(arr_ty, _)) => {
21 if !matches!(arr_ty.kind(), ty::Uint(UintTy::U8)) {
24 if matches!(from_ty.kind(), ty::Float(_)) && const_context {
25 // TODO: Remove when const_float_bits_conv is stabilized
32 TRANSMUTE_NUM_TO_BYTES,
34 &format!("transmute from a `{}` to a `{}`", from_ty, to_ty),
36 let arg = sugg::Sugg::hir(cx, &args[0], "..");
39 "consider using `to_ne_bytes()`",
40 format!("{}.to_ne_bytes()", arg),
41 Applicability::Unspecified,