1 use super::TRANSMUTE_INT_TO_FLOAT;
2 use crate::utils::sugg;
3 use clippy_utils::diagnostics::span_lint_and_then;
4 use rustc_errors::Applicability;
6 use rustc_lint::LateContext;
7 use rustc_middle::ty::{self, Ty};
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(_)) if !const_context => {
23 TRANSMUTE_INT_TO_FLOAT,
25 &format!("transmute from a `{}` to a `{}`", from_ty, to_ty),
27 let arg = sugg::Sugg::hir(cx, &args[0], "..");
28 let arg = if let ty::Int(int_ty) = from_ty.kind() {
31 int_ty.bit_width().map_or_else(|| "size".to_string(), |v| v.to_string())
39 format!("{}::from_bits({})", to_ty, arg.to_string()),
40 Applicability::Unspecified,