1 use super::TRANSMUTE_INT_TO_BOOL;
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};
11 /// Checks for `transmute_int_to_bool` lint.
12 /// Returns `true` if it's triggered, otherwise returns `false`.
13 pub(super) fn check<'tcx>(
14 cx: &LateContext<'tcx>,
18 args: &'tcx [Expr<'_>],
20 match (&from_ty.kind(), &to_ty.kind()) {
21 (ty::Int(ty::IntTy::I8) | ty::Uint(ty::UintTy::U8), ty::Bool) => {
24 TRANSMUTE_INT_TO_BOOL,
26 &format!("transmute from a `{}` to a `bool`", from_ty),
28 let arg = sugg::Sugg::hir(cx, &args[0], "..");
29 let zero = sugg::Sugg::NonParen(Cow::from("0"));
33 sugg::make_binop(ast::BinOpKind::Ne, &arg, &zero).to_string(),
34 Applicability::Unspecified,