-use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
+use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then};
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
use clippy_utils::{eq_expr_value, get_trait_def_id, paths};
///
/// ### Example
/// ```ignore
- /// if a && true // should be: if a
- /// if !(a == b) // should be: if a != b
+ /// if a && true {}
+ /// if !(a == b) {}
+ /// ```
+ ///
+ /// Use instead:
+ /// ```rust,ignore
+ /// if a {}
+ /// if a != b {}
/// ```
#[clippy::version = "pre 1.29.0"]
pub NONMINIMAL_BOOL,
/// Ignores short circuiting behavior.
///
/// ### Example
- /// ```ignore
+ /// ```rust,ignore
+ /// // The `b` is unnecessary, the expression is equivalent to `if a`.
/// if a && b || a { ... }
/// ```
- /// The `b` is unnecessary, the expression is equivalent to `if a`.
+ ///
+ /// Use instead:
+ /// ```rust,ignore
+ /// if a {}
+ /// ```
#[clippy::version = "pre 1.29.0"]
pub LOGIC_BUG,
correctness,
}
for (n, expr) in self.terminals.iter().enumerate() {
if eq_expr_value(self.cx, e, expr) {
- #[allow(clippy::cast_possible_truncation)]
+ #[expect(clippy::cast_possible_truncation)]
return Ok(Bool::Term(n as u8));
}
if eq_expr_value(self.cx, e_lhs, expr_lhs);
if eq_expr_value(self.cx, e_rhs, expr_rhs);
then {
- #[allow(clippy::cast_possible_truncation)]
+ #[expect(clippy::cast_possible_truncation)]
return Ok(Bool::Not(Box::new(Bool::Term(n as u8))));
}
}
let n = self.terminals.len();
self.terminals.push(e);
if n < 32 {
- #[allow(clippy::cast_possible_truncation)]
+ #[expect(clippy::cast_possible_truncation)]
Ok(Bool::Term(n as u8))
} else {
Err("too many literals".to_owned())
continue 'simplified;
}
if stats.terminals[i] != 0 && simplified_stats.terminals[i] == 0 {
- span_lint_and_then(
+ span_lint_hir_and_then(
self.cx,
LOGIC_BUG,
+ e.hir_id,
e.span,
"this boolean expression contains a logic bug",
|diag| {
}
}
let nonminimal_bool_lint = |suggestions: Vec<_>| {
- span_lint_and_then(
+ span_lint_hir_and_then(
self.cx,
NONMINIMAL_BOOL,
+ e.hir_id,
e.span,
"this boolean expression can be simplified",
|diag| {