/// ### Example
/// ```rust
/// # let x = vec![1];
- /// x.iter().zip(0..x.len());
+ /// let _ = x.iter().zip(0..x.len());
/// ```
- /// Could be written as
+ ///
+ /// Use instead:
/// ```rust
/// # let x = vec![1];
- /// x.iter().enumerate();
+ /// let _ = x.iter().enumerate();
/// ```
#[clippy::version = "pre 1.29.0"]
pub RANGE_ZIP_WITH_LEN,
/// ([#3307](https://github.com/rust-lang/rust-clippy/issues/3307)).
///
/// ### Example
- /// ```rust,ignore
- /// for x..(y+1) { .. }
+ /// ```rust
+ /// # let x = 0;
+ /// # let y = 1;
+ /// for i in x..(y+1) {
+ /// // ..
+ /// }
/// ```
- /// Could be written as
- /// ```rust,ignore
- /// for x..=y { .. }
+ ///
+ /// Use instead:
+ /// ```rust
+ /// # let x = 0;
+ /// # let y = 1;
+ /// for i in x..=y {
+ /// // ..
+ /// }
/// ```
#[clippy::version = "pre 1.29.0"]
pub RANGE_PLUS_ONE,
/// ([#3307](https://github.com/rust-lang/rust-clippy/issues/3307)).
///
/// ### Example
- /// ```rust,ignore
- /// for x..=(y-1) { .. }
+ /// ```rust
+ /// # let x = 0;
+ /// # let y = 1;
+ /// for i in x..=(y-1) {
+ /// // ..
+ /// }
/// ```
- /// Could be written as
- /// ```rust,ignore
- /// for x..y { .. }
+ ///
+ /// Use instead:
+ /// ```rust
+ /// # let x = 0;
+ /// # let y = 1;
+ /// for i in x..y {
+ /// // ..
+ /// }
/// ```
#[clippy::version = "pre 1.29.0"]
pub RANGE_MINUS_ONE,
},
ExprKind::Binary(ref op, l, r) => {
if meets_msrv(self.msrv, msrvs::RANGE_CONTAINS) {
- check_possible_range_contains(cx, op.node, l, r, expr);
+ check_possible_range_contains(cx, op.node, l, r, expr, expr.span);
}
},
_ => {},
left: &Expr<'_>,
right: &Expr<'_>,
expr: &Expr<'_>,
+ span: Span,
) {
if in_constant(cx, expr.hir_id) {
return;
}
- let span = expr.span;
let combine_and = match op {
BinOpKind::And | BinOpKind::BitAnd => true,
BinOpKind::Or | BinOpKind::BitOr => false,
);
}
}
+
+ // If the LHS is the same operator, we have to recurse to get the "real" RHS, since they have
+ // the same operator precedence
+ if_chain! {
+ if let ExprKind::Binary(ref lhs_op, _left, new_lhs) = left.kind;
+ if op == lhs_op.node;
+ let new_span = Span::new(new_lhs.span.lo(), right.span.hi(), expr.span.ctxt(), expr.span.parent());
+ if let Some(snip) = &snippet_opt(cx, new_span);
+ // Do not continue if we have mismatched number of parens, otherwise the suggestion is wrong
+ if snip.matches('(').count() == snip.matches(')').count();
+ then {
+ check_possible_range_contains(cx, op, new_lhs, right, expr, new_span);
+ }
+ }
}
struct RangeBounds<'a> {