Skip to content

Commit

Permalink
Rollup merge of rust-lang#58690 - kenta7777:reduce-code-repetition-mi…
Browse files Browse the repository at this point in the history
…ri-related, r=oli-obk

Reduce a Code Repetition like `(n << amt) >> amt`

Fixes a part of [rust-lang#49937](rust-lang#49937).
  • Loading branch information
Centril authored Feb 25, 2019
2 parents 5f910fa + 423ae56 commit 53f15f2
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::hir;
use crate::hir::def_id::DefId;
use crate::infer::canonical::Canonical;
use crate::mir::interpret::ConstValue;
use crate::mir::interpret::{ConstValue, truncate};
use crate::middle::region;
use polonius_engine::Atom;
use rustc_data_structures::indexed_vec::Idx;
Expand Down Expand Up @@ -2118,8 +2118,7 @@ impl<'tcx> Const<'tcx> {
let size = tcx.layout_of(ty).unwrap_or_else(|e| {
panic!("could not compute layout for {:?}: {:?}", ty, e)
}).size;
let shift = 128 - size.bits();
let truncated = (bits << shift) >> shift;
let truncated = truncate(bits, size);
assert_eq!(truncated, bits, "from_bits called with untruncated value");
Self::from_scalar(Scalar::Bits { bits, size: size.bytes() as u8 }, ty.value)
}
Expand Down

0 comments on commit 53f15f2

Please sign in to comment.