Skip to content

Commit 9778a81

Browse files
committed
Improve macros with reduced repetition
1 parent 7476ba4 commit 9778a81

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl<'tcx> Constructor<'tcx> {
273273
}
274274
}
275275

276-
#[derive(Clone, Debug)]
276+
#[derive(Clone)]
277277
pub enum Usefulness<'tcx> {
278278
Useful,
279279
UsefulWithWitness(Vec<Witness<'tcx>>),
@@ -468,13 +468,18 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
468468
}
469469
ty::TyInt(int_ty) if exhaustive_integer_patterns => {
470470
use syntax::ast::IntTy::*;
471+
macro_rules! min_max_ty {
472+
($ity:ident, $uty:ty, $sty:expr) => {
473+
($ity::MIN as $uty as u128, $ity::MAX as $uty as u128, $sty)
474+
}
475+
}
471476
let (min, max, ty) = match int_ty {
472-
Isize => (isize::MIN as usize as u128, isize::MAX as usize as u128, cx.tcx.types.isize),
473-
I8 => ( i8::MIN as u8 as u128, i8::MAX as u8 as u128, cx.tcx.types.i8),
474-
I16 => ( i16::MIN as u16 as u128, i16::MAX as u16 as u128, cx.tcx.types.i16),
475-
I32 => ( i32::MIN as u32 as u128, i32::MAX as u32 as u128, cx.tcx.types.i32),
476-
I64 => ( i64::MIN as u64 as u128, i64::MAX as u64 as u128, cx.tcx.types.i64),
477-
I128 => ( i128::MIN as u128 as u128, i128::MAX as u128 as u128, cx.tcx.types.i128),
477+
Isize => min_max_ty!(isize, usize, cx.tcx.types.isize),
478+
I8 => min_max_ty!(i8, u8, cx.tcx.types.i8),
479+
I16 => min_max_ty!(i16, u16, cx.tcx.types.i16),
480+
I32 => min_max_ty!(i32, u32, cx.tcx.types.i32),
481+
I64 => min_max_ty!(i64, u64, cx.tcx.types.i64),
482+
I128 => min_max_ty!(i128, u128, cx.tcx.types.i128),
478483
};
479484
value_constructors = true;
480485
vec![ConstantRange(ty::Const::from_bits(cx.tcx, min, ty),
@@ -653,8 +658,8 @@ impl<'tcx> Interval<'tcx> {
653658
match ty.sty {
654659
ty::TyInt(int_ty) => {
655660
macro_rules! offset_sign_for_ty {
656-
($ity:ty, $uty:ty, $min:expr) => {{
657-
let min = Wrapping($min as $uty);
661+
($ity:ident, $uty:ty) => {{
662+
let min = Wrapping($ity::MIN as $uty);
658663
if forwards {
659664
((Wrapping(lo as $uty) + min).0 as u128,
660665
(Wrapping(hi as $uty) + min).0 as u128)
@@ -665,12 +670,12 @@ impl<'tcx> Interval<'tcx> {
665670
}}
666671
}
667672
match int_ty {
668-
Isize => offset_sign_for_ty!(isize, usize, isize::MIN),
669-
I8 => offset_sign_for_ty!(i8, u8, i8::MIN),
670-
I16 => offset_sign_for_ty!(i16, u16, i16::MIN),
671-
I32 => offset_sign_for_ty!(i32, u32, i32::MIN),
672-
I64 => offset_sign_for_ty!(i64, u64, i64::MIN),
673-
I128 => offset_sign_for_ty!(i128, u128, i128::MIN),
673+
Isize => offset_sign_for_ty!(isize, usize),
674+
I8 => offset_sign_for_ty!(i8, u8),
675+
I16 => offset_sign_for_ty!(i16, u16),
676+
I32 => offset_sign_for_ty!(i32, u32),
677+
I64 => offset_sign_for_ty!(i64, u64),
678+
I128 => offset_sign_for_ty!(i128, u128),
674679
}
675680
}
676681
ty::TyUint(_) | ty::TyChar => {

0 commit comments

Comments
 (0)