use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
+use rustc_errors::Applicability;
use syntax::ast::*;
use crate::utils::{snippet_opt, span_lint_and_then};
-/// **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.
-///
-/// **Example:**
-/// ```rust
-/// x >= y + 1
-/// ```
-///
-/// Could be written:
-///
-/// ```rust
-/// x > y
-/// ```
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.
+ ///
+ /// **Example:**
+ /// ```rust
+ /// x >= y + 1
+ /// ```
+ ///
+ /// Could be written:
+ ///
+ /// ```rust
+ /// x > y
+ /// ```
pub INT_PLUS_ONE,
complexity,
"instead of using x >= y + 1, use x > y"
fn get_lints(&self) -> LintArray {
lint_array!(INT_PLUS_ONE)
}
+
+ fn name(&self) -> &'static str {
+ "IntPlusOne"
+ }
}
// cases:
}
impl IntPlusOne {
- #[allow(cast_sign_loss)]
+ #[allow(clippy::cast_sign_loss)]
fn check_lit(&self, lit: &Lit, target_value: i128) -> bool {
if let LitKind::Int(value, ..) = lit.node {
return value == (target_value as u128);
}
fn emit_warning(&self, cx: &EarlyContext<'_>, block: &Expr, recommendation: String) {
- span_lint_and_then(cx, INT_PLUS_ONE, block.span, "Unnecessary `>= y + 1` or `x - 1 >=`", |db| {
- db.span_suggestion(block.span, "change `>= y + 1` to `> y` as shown", recommendation);
- });
+ span_lint_and_then(
+ cx,
+ INT_PLUS_ONE,
+ block.span,
+ "Unnecessary `>= y + 1` or `x - 1 >=`",
+ |db| {
+ db.span_suggestion(
+ block.span,
+ "change `>= y + 1` to `> y` as shown",
+ recommendation,
+ Applicability::MachineApplicable, // snippet
+ );
+ },
+ );
}
}