Skip to content

Commit

Permalink
get rid of visit_constant in thir visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
b-naber committed Apr 6, 2022
1 parent bca346b commit 2f78075
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions clippy_lints/src/matches/overlapping_arms.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clippy_utils::consts::{constant, constant_full_int, FullInt};
use clippy_utils::consts::{constant, constant_full_int, miri_to_const, FullInt};
use clippy_utils::diagnostics::span_lint_and_note;
use core::cmp::Ordering;
use rustc_hir::{Arm, Expr, PatKind, RangeEnd};
Expand Down Expand Up @@ -32,15 +32,16 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
.filter_map(|arm| {
if let Arm { pat, guard: None, .. } = *arm {
if let PatKind::Range(ref lhs, ref rhs, range_end) = pat.kind {
let lhs_val = match lhs {
Some(lhs) => constant(cx, cx.typeck_results(), lhs)?.0.int_value(cx, ty)?,
None => FullInt::U(ty.numeric_min_val(cx.tcx)?),
let lhs_const = match lhs {
Some(lhs) => constant(cx, cx.typeck_results(), lhs)?.0,
None => miri_to_const(ty.numeric_min_val(cx.tcx)?)?,
};
let rhs_val = match rhs {
Some(rhs) => constant(cx, cx.typeck_results(), rhs)?.0.int_value(cx, ty)?,
None => FullInt::U(ty.numeric_max_val(cx.tcx)?),
let rhs_const = match rhs {
Some(rhs) => constant(cx, cx.typeck_results(), rhs)?.0,
None => miri_to_const(ty.numeric_max_val(cx.tcx)?)?,
};

let lhs_val = lhs_const.int_value(cx, ty)?;
let rhs_val = rhs_const.int_value(cx, ty)?;
let rhs_bound = match range_end {
RangeEnd::Included => EndBound::Included(rhs_val),
RangeEnd::Excluded => EndBound::Excluded(rhs_val),
Expand Down

0 comments on commit 2f78075

Please sign in to comment.