Skip to content

Commit

Permalink
Auto merge of #6382 - giraffate:fix_fp_in_manual_range_contains_when_…
Browse files Browse the repository at this point in the history
…const_fn, r=llogiq

Fix FP of `manual_range_contains` in `const fn`

Fix #6373.

changelog: Fix FP of `manual_range_contains` in `const fn`
  • Loading branch information
bors committed Dec 7, 2020
2 parents c1664c5 + 14736ab commit e02fa2e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
13 changes: 9 additions & 4 deletions clippy_lints/src/ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use std::cmp::Ordering;

use crate::utils::sugg::Sugg;
use crate::utils::{
get_parent_expr, is_integer_const, single_segment_path, snippet, snippet_opt, snippet_with_applicability,
span_lint, span_lint_and_sugg, span_lint_and_then,
get_parent_expr, in_constant, is_integer_const, single_segment_path, snippet, snippet_opt,
snippet_with_applicability, span_lint, span_lint_and_sugg, span_lint_and_then,
};
use crate::utils::{higher, SpanlessEq};

Expand Down Expand Up @@ -175,7 +175,7 @@ impl<'tcx> LateLintPass<'tcx> for Ranges {
check_range_zip_with_len(cx, path, args, expr.span);
},
ExprKind::Binary(ref op, ref l, ref r) => {
check_possible_range_contains(cx, op.node, l, r, expr.span);
check_possible_range_contains(cx, op.node, l, r, expr);
},
_ => {},
}
Expand All @@ -186,7 +186,12 @@ impl<'tcx> LateLintPass<'tcx> for Ranges {
}
}

fn check_possible_range_contains(cx: &LateContext<'_>, op: BinOpKind, l: &Expr<'_>, r: &Expr<'_>, span: Span) {
fn check_possible_range_contains(cx: &LateContext<'_>, op: BinOpKind, l: &Expr<'_>, r: &Expr<'_>, expr: &Expr<'_>) {
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,
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/range_contains.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ fn main() {
(0. ..1.).contains(&y);
!(0. ..=1.).contains(&y);
}

// Fix #6373
pub const fn in_range(a: i32) -> bool {
3 <= a && a <= 20
}
5 changes: 5 additions & 0 deletions tests/ui/range_contains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ fn main() {
y >= 0. && y < 1.;
y < 0. || y > 1.;
}

// Fix #6373
pub const fn in_range(a: i32) -> bool {
3 <= a && a <= 20
}

0 comments on commit e02fa2e

Please sign in to comment.