//! lint on blocks unnecessarily using >= with a + 1 or - 1
+use rustc_ast::ast::{BinOpKind, Expr, ExprKind, Lit, LitKind};
use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
-use syntax::ast::*;
-use crate::utils::{snippet_opt, span_lint_and_then};
+use crate::utils::{snippet_opt, span_lint_and_sugg};
declare_clippy_lint! {
/// **What it does:** Checks for usage of `x >= y + 1` or `x - 1 >= y` (and `<=`) in a block
///
- ///
/// **Why is this bad?** Readability -- better to use `> y` instead of `>= y + 1`.
///
/// **Known problems:** None.
}
fn emit_warning(cx: &EarlyContext<'_>, block: &Expr, recommendation: String) {
- span_lint_and_then(
+ span_lint_and_sugg(
cx,
INT_PLUS_ONE,
block.span,
- "Unnecessary `>= y + 1` or `x - 1 >=`",
- |db| {
- db.span_suggestion(
- block.span,
- "change it to",
- recommendation,
- Applicability::MachineApplicable, // snippet
- );
- },
+ "unnecessary `>= y + 1` or `x - 1 >=`",
+ "change it to",
+ recommendation,
+ Applicability::MachineApplicable, // snippet
);
}
}
impl EarlyLintPass for IntPlusOne {
fn check_expr(&mut self, cx: &EarlyContext<'_>, item: &Expr) {
if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = item.kind {
- if let Some(ref rec) = Self::check_binop(cx, kind.node, lhs, rhs) {
- Self::emit_warning(cx, item, rec.clone());
+ if let Some(rec) = Self::check_binop(cx, kind.node, lhs, rhs) {
+ Self::emit_warning(cx, item, rec);
}
}
}