Skip to content

Commit cc028e2

Browse files
authored
Rollup merge of rust-lang#59208 - kenta7777:reduce-code-repetition, r=oli-obk
Reduce a Code Repetition Related to Bit Operation This PR is related to [rust-lang#49937](rust-lang#49937). Should I do more commits about [`FIXME(49937)`](https://github.com/rust-lang/rust/search?q=FIXME%2849937%29&unscoped_q=FIXME%2849937%29) in this PR?
2 parents 952808e + a8fa1a1 commit cc028e2

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/librustc_mir/build/matches/simplify.rs

-2
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
114114
(Some(('\u{0000}' as u128, '\u{10FFFF}' as u128, Size::from_bits(32))), 0)
115115
}
116116
ty::Int(ity) => {
117-
// FIXME(49937): refactor these bit manipulations into interpret.
118117
let size = Integer::from_attr(&tcx, SignedInt(ity)).size();
119118
let max = truncate(u128::max_value(), size);
120119
let bias = 1u128 << (size.bits() - 1);
121120
(Some((0, max, size)), bias)
122121
}
123122
ty::Uint(uty) => {
124-
// FIXME(49937): refactor these bit manipulations into interpret.
125123
let size = Integer::from_attr(&tcx, UnsignedInt(uty)).size();
126124
let max = truncate(u128::max_value(), size);
127125
(Some((0, max, size)), 0)

src/librustc_mir/hair/pattern/_match.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ use rustc::ty::{self, subst::SubstsRef, Ty, TyCtxt, TypeFoldable, Const};
172172
use rustc::ty::layout::{Integer, IntegerExt, VariantIdx, Size};
173173

174174
use rustc::mir::Field;
175-
use rustc::mir::interpret::{ConstValue, Scalar};
175+
use rustc::mir::interpret::{ConstValue, Scalar, truncate};
176176
use rustc::util::common::ErrorReported;
177177

178178
use syntax::attr::{SignedInt, UnsignedInt};
@@ -678,16 +678,14 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
678678
]
679679
}
680680
ty::Int(ity) => {
681-
// FIXME(49937): refactor these bit manipulations into interpret.
682681
let bits = Integer::from_attr(&cx.tcx, SignedInt(ity)).size().bits() as u128;
683682
let min = 1u128 << (bits - 1);
684-
let max = (1u128 << (bits - 1)) - 1;
683+
let max = min - 1;
685684
vec![ConstantRange(min, max, pcx.ty, RangeEnd::Included)]
686685
}
687686
ty::Uint(uty) => {
688-
// FIXME(49937): refactor these bit manipulations into interpret.
689-
let bits = Integer::from_attr(&cx.tcx, UnsignedInt(uty)).size().bits() as u128;
690-
let max = !0u128 >> (128 - bits);
687+
let size = Integer::from_attr(&cx.tcx, UnsignedInt(uty)).size();
688+
let max = truncate(u128::max_value(), size);
691689
vec![ConstantRange(0, max, pcx.ty, RangeEnd::Included)]
692690
}
693691
_ => {

0 commit comments

Comments
 (0)