1 use super::TRANSMUTE_INT_TO_CHAR;
2 use clippy_utils::diagnostics::span_lint_and_then;
3 use clippy_utils::sugg;
5 use rustc_errors::Applicability;
7 use rustc_lint::LateContext;
8 use rustc_middle::ty::{self, Ty};
10 /// Checks for `transmute_int_to_char` lint.
11 /// Returns `true` if it's triggered, otherwise returns `false`.
12 pub(super) fn check<'tcx>(
13 cx: &LateContext<'tcx>,
17 args: &'tcx [Expr<'_>],
19 match (&from_ty.kind(), &to_ty.kind()) {
20 (ty::Int(ty::IntTy::I32) | ty::Uint(ty::UintTy::U32), &ty::Char) => {
23 TRANSMUTE_INT_TO_CHAR,
25 &format!("transmute from a `{}` to a `char`", from_ty),
27 let arg = sugg::Sugg::hir(cx, &args[0], "..");
28 let arg = if let ty::Int(_) = from_ty.kind() {
29 arg.as_ty(ast::UintTy::U32.name_str())
36 format!("std::char::from_u32({}).unwrap()", arg),
37 Applicability::Unspecified,