mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-18 00:53:31 +00:00
Fix FP of manual_range_contains
in const fn
This commit is contained in:
parent
27fd6ed581
commit
26c61c7e49
3 changed files with 18 additions and 3 deletions
|
@ -14,7 +14,7 @@ use std::cmp::Ordering;
|
|||
|
||||
use crate::utils::sugg::Sugg;
|
||||
use crate::utils::{
|
||||
get_parent_expr, is_integer_const, meets_msrv, single_segment_path, snippet, snippet_opt,
|
||||
get_parent_expr, in_constant, is_integer_const, meets_msrv, single_segment_path, snippet, snippet_opt,
|
||||
snippet_with_applicability, span_lint, span_lint_and_sugg, span_lint_and_then,
|
||||
};
|
||||
use crate::utils::{higher, SpanlessEq};
|
||||
|
@ -190,7 +190,7 @@ impl<'tcx> LateLintPass<'tcx> for Ranges {
|
|||
},
|
||||
ExprKind::Binary(ref op, ref l, ref r) => {
|
||||
if meets_msrv(self.msrv.as_ref(), &MANUAL_RANGE_CONTAINS_MSRV) {
|
||||
check_possible_range_contains(cx, op.node, l, r, expr.span);
|
||||
check_possible_range_contains(cx, op.node, l, r, expr);
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
|
@ -203,7 +203,12 @@ impl<'tcx> LateLintPass<'tcx> for Ranges {
|
|||
extract_msrv_attr!(LateContext);
|
||||
}
|
||||
|
||||
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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue