1 use clippy_utils::diagnostics::span_lint;
2 use clippy_utils::macros::{find_assert_eq_args, root_macro_call_first_node};
3 use rustc_hir::{BinOpKind, Expr, ExprKind};
4 use rustc_lint::LateContext;
8 pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
9 if expr.span.from_expansion() {
10 if let Some(macro_call) = root_macro_call_first_node(cx, expr) {
11 let macro_name = cx.tcx.item_name(macro_call.def_id);
12 let result = match macro_name.as_str() {
13 "assert_eq" | "debug_assert_eq" => "succeed",
14 "assert_ne" | "debug_assert_ne" => "fail",
17 let Some ((left, _, _)) = find_assert_eq_args(cx, expr, macro_call.expn) else { return };
18 if !cx.typeck_results().expr_ty(left).is_unit() {
25 &format!("`{macro_name}` of unit values detected. This will always {result}"),
31 if let ExprKind::Binary(ref cmp, left, _) = expr.kind {
33 if op.is_comparison() && cx.typeck_results().expr_ty(left).is_unit() {
34 let result = match op {
35 BinOpKind::Eq | BinOpKind::Le | BinOpKind::Ge => "true",
43 "{}-comparison of unit values detected. This will always be {result}",