1 use super::TRANSMUTE_INT_TO_FLOAT;
2 use crate::utils::{span_lint_and_then, sugg};
3 use rustc_errors::Applicability;
5 use rustc_lint::LateContext;
6 use rustc_middle::ty::{self, Ty};
8 /// Checks for `transmute_int_to_float` lint.
9 /// Returns `true` if it's triggered, otherwise returns `false`.
10 pub(super) fn check<'tcx>(
11 cx: &LateContext<'tcx>,
15 args: &'tcx [Expr<'_>],
18 match (&from_ty.kind(), &to_ty.kind()) {
19 (ty::Int(_) | ty::Uint(_), ty::Float(_)) if !const_context => {
22 TRANSMUTE_INT_TO_FLOAT,
24 &format!("transmute from a `{}` to a `{}`", from_ty, to_ty),
26 let arg = sugg::Sugg::hir(cx, &args[0], "..");
27 let arg = if let ty::Int(int_ty) = from_ty.kind() {
30 int_ty.bit_width().map_or_else(|| "size".to_string(), |v| v.to_string())
38 format!("{}::from_bits({})", to_ty, arg.to_string()),
39 Applicability::Unspecified,