Skip to content

Commit efe6954

Browse files
authored
Rollup merge of rust-lang#58690 - kenta7777:reduce-code-repetition-miri-related, r=oli-obk
Reduce a Code Repetition like `(n << amt) >> amt` Fixes a part of [rust-lang#49937](rust-lang#49937).
2 parents 9a03755 + 423ae56 commit efe6954

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Diff for: 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)