1 use clippy_utils::diagnostics::span_lint_and_then;
2 use clippy_utils::source::snippet_opt;
3 use rustc_errors::Applicability;
4 use rustc_hir::{BinOpKind, Expr, ExprKind};
5 use rustc_lint::LateContext;
7 use super::NEEDLESS_BITWISE_BOOL;
9 pub(super) fn check(cx: &LateContext<'_>, e: &Expr<'_>, op: BinOpKind, lhs: &Expr<'_>, rhs: &Expr<'_>) {
10 let op_str = match op {
11 BinOpKind::BitAnd => "&&",
12 BinOpKind::BitOr => "||",
17 ExprKind::Call(..) | ExprKind::MethodCall(..) | ExprKind::Binary(..) | ExprKind::Unary(..)
18 ) && cx.typeck_results().expr_ty(e).is_bool()
19 && !rhs.can_have_side_effects()
23 NEEDLESS_BITWISE_BOOL,
25 "use of bitwise operator instead of lazy operator between booleans",
27 if let Some(lhs_snip) = snippet_opt(cx, lhs.span)
28 && let Some(rhs_snip) = snippet_opt(cx, rhs.span)
30 let sugg = format!("{lhs_snip} {op_str} {rhs_snip}");
31 diag.span_suggestion(e.span, "try", sugg, Applicability::MachineApplicable);