]> git.lizzy.rs Git - rust.git/commitdiff
reduced a code repetition related to bit operation.
authorkenta7777 <k.hasegw7@gmail.com>
Fri, 15 Mar 2019 12:48:05 +0000 (21:48 +0900)
committerkenta7777 <k.hasegw7@gmail.com>
Fri, 15 Mar 2019 12:48:05 +0000 (21:48 +0900)
src/librustc_mir/hair/pattern/_match.rs

index 586a3fdb907ee7a1c4841ed4324a20a9128ce4bf..76e04d349f15bc679bab7aaec4a04859d6182bbe 100644 (file)
 use rustc::ty::layout::{Integer, IntegerExt, VariantIdx, Size};
 
 use rustc::mir::Field;
-use rustc::mir::interpret::{ConstValue, Scalar};
+use rustc::mir::interpret::{ConstValue, Scalar, truncate};
 use rustc::util::common::ErrorReported;
 
 use syntax::attr::{SignedInt, UnsignedInt};
@@ -685,9 +685,8 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
             vec![ConstantRange(min, max, pcx.ty, RangeEnd::Included)]
         }
         ty::Uint(uty) => {
-            // FIXME(49937): refactor these bit manipulations into interpret.
-            let bits = Integer::from_attr(&cx.tcx, UnsignedInt(uty)).size().bits() as u128;
-            let max = !0u128 >> (128 - bits);
+            let size = Integer::from_attr(&cx.tcx, UnsignedInt(uty)).size();
+            let max = truncate(u128::max_value(), size);
             vec![ConstantRange(0, max, pcx.ty, RangeEnd::Included)]
         }
         _ => {