Skip to content

Commit 423ae56

Browse files
committed
reduce a code repetition like (n << amt) >> amt
1 parent aadbc45 commit 423ae56

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/librustc/ty/sty.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::hir;
44
use crate::hir::def_id::DefId;
55
use crate::infer::canonical::Canonical;
6-
use crate::mir::interpret::ConstValue;
6+
use crate::mir::interpret::{ConstValue, truncate};
77
use crate::middle::region;
88
use polonius_engine::Atom;
99
use rustc_data_structures::indexed_vec::Idx;
@@ -2118,8 +2118,7 @@ impl<'tcx> Const<'tcx> {
21182118
let size = tcx.layout_of(ty).unwrap_or_else(|e| {
21192119
panic!("could not compute layout for {:?}: {:?}", ty, e)
21202120
}).size;
2121-
let shift = 128 - size.bits();
2122-
let truncated = (bits << shift) >> shift;
2121+
let truncated = truncate(bits, size);
21232122
assert_eq!(truncated, bits, "from_bits called with untruncated value");
21242123
Self::from_scalar(Scalar::Bits { bits, size: size.bytes() as u8 }, ty.value)
21252124
}

0 commit comments

Comments
 (0)