-// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
//! lint on blocks unnecessarily using >= with a + 1 or - 1
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
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:
block.span,
"Unnecessary `>= y + 1` or `x - 1 >=`",
|db| {
- db.span_suggestion_with_applicability(
+ db.span_suggestion(
block.span,
"change `>= y + 1` to `> y` as shown",
recommendation,