diff options
| author | varkor <github@varkor.com> | 2018-05-21 23:51:01 +0100 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2018-08-16 20:09:04 +0100 |
| commit | 7695bd0be9cc6d08b9d58c1c0ef193458857ece7 (patch) | |
| tree | e400d4ef361fd57adbe70a9e0662b755281c625d | |
| parent | c00fd8f58c9c7780b83fbb4e5e2e419f1ddd37e2 (diff) | |
| download | rust-7695bd0be9cc6d08b9d58c1c0ef193458857ece7.tar.gz rust-7695bd0be9cc6d08b9d58c1c0ef193458857ece7.zip | |
Use bit operators for min_max_ty
| -rw-r--r-- | src/librustc_mir/hair/pattern/_match.rs | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index 204d3ea8c9c..9f0f07f2a9c 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -472,18 +472,20 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>, } ty::TyInt(int_ty) if exhaustive_integer_patterns => { use syntax::ast::IntTy::*; - macro_rules! min_max_ty { - ($ity:ident, $uty:ty, $sty:expr) => { - ($ity::MIN as $uty as u128, $ity::MAX as $uty as u128, $sty) - } - } + let min_max_ty = |sty| { + let size = cx.tcx.layout_of(ty::ParamEnv::reveal_all().and(sty)) + .unwrap().size.bits() as i128; + let min = -(1 << (size - 1)); + let max = (1 << (size - 1)) - 1; + (min as u128, max as u128, sty) + }; let (min, max, ty) = match int_ty { - Isize => min_max_ty!(isize, usize, cx.tcx.types.isize), - I8 => min_max_ty!(i8, u8, cx.tcx.types.i8), - I16 => min_max_ty!(i16, u16, cx.tcx.types.i16), - I32 => min_max_ty!(i32, u32, cx.tcx.types.i32), - I64 => min_max_ty!(i64, u64, cx.tcx.types.i64), - I128 => min_max_ty!(i128, u128, cx.tcx.types.i128), + Isize => min_max_ty(cx.tcx.types.isize), + I8 => min_max_ty(cx.tcx.types.i8), + I16 => min_max_ty(cx.tcx.types.i16), + I32 => min_max_ty(cx.tcx.types.i32), + I64 => min_max_ty(cx.tcx.types.i64), + I128 => min_max_ty(cx.tcx.types.i128), }; value_constructors = true; vec