Skip to content

Commit bca346b

Browse files
committed
rebase and use ty::Const in patterns again
1 parent bb5b250 commit bca346b

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

clippy_lints/src/matches/overlapping_arms.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::consts::{constant, constant_full_int, miri_to_const, FullInt};
1+
use clippy_utils::consts::{constant, constant_full_int, FullInt};
22
use clippy_utils::diagnostics::span_lint_and_note;
33
use core::cmp::Ordering;
44
use rustc_hir::{Arm, Expr, PatKind, RangeEnd};
@@ -32,18 +32,15 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
3232
.filter_map(|arm| {
3333
if let Arm { pat, guard: None, .. } = *arm {
3434
if let PatKind::Range(ref lhs, ref rhs, range_end) = pat.kind {
35-
let lhs_const = match lhs {
36-
Some(lhs) => constant(cx, cx.typeck_results(), lhs)?.0,
37-
None => miri_to_const(ty.numeric_min_val(cx.tcx)?)?,
35+
let lhs_val = match lhs {
36+
Some(lhs) => constant(cx, cx.typeck_results(), lhs)?.0.int_value(cx, ty)?,
37+
None => FullInt::U(ty.numeric_min_val(cx.tcx)?),
3838
};
39-
let rhs_const = match rhs {
40-
Some(rhs) => constant(cx, cx.typeck_results(), rhs)?.0,
41-
None => miri_to_const(ty.numeric_max_val(cx.tcx)?)?,
39+
let rhs_val = match rhs {
40+
Some(rhs) => constant(cx, cx.typeck_results(), rhs)?.0.int_value(cx, ty)?,
41+
None => FullInt::U(ty.numeric_max_val(cx.tcx)?),
4242
};
4343

44-
let lhs_val = lhs_const.int_value(cx, ty)?;
45-
let rhs_val = rhs_const.int_value(cx, ty)?;
46-
4744
let rhs_bound = match range_end {
4845
RangeEnd::Included => EndBound::Included(rhs_val),
4946
RangeEnd::Excluded => EndBound::Excluded(rhs_val),

clippy_lints/src/neg_multiply.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for NegMultiply {
5353
fn check_mul(cx: &LateContext<'_>, span: Span, lit: &Expr<'_>, exp: &Expr<'_>) {
5454
if_chain! {
5555
if let ExprKind::Lit(ref l) = lit.kind;
56-
if consts::lit_to_constant(&l.node, cx.typeck_results().expr_ty_opt(lit)) == Constant::Int(1);
56+
if consts::lit_to_mir_constant(&l.node, cx.typeck_results().expr_ty_opt(lit)) == Constant::Int(1);
5757
if cx.typeck_results().expr_ty(exp).is_integral();
5858

5959
then {

clippy_utils/src/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl Constant {
179179
}
180180

181181
/// Parses a `LitKind` to a `Constant`.
182-
pub fn lit_to_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
182+
pub fn lit_to_mir_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
183183
match *lit {
184184
LitKind::Str(ref is, _) => Constant::Str(is.to_string()),
185185
LitKind::Byte(b) => Constant::Int(u128::from(b)),
@@ -301,7 +301,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
301301
if is_direct_expn_of(e.span, "cfg").is_some() {
302302
None
303303
} else {
304-
Some(lit_to_constant(&lit.node, self.typeck_results.expr_ty_opt(e)))
304+
Some(lit_to_mir_constant(&lit.node, self.typeck_results.expr_ty_opt(e)))
305305
}
306306
},
307307
ExprKind::Array(vec) => self.multi(vec).map(Constant::Vec),

0 commit comments

Comments
 (0)