Rollup merge of #56233 - kenta7777:kenta7777#49937, r=oli-obk

Miri and miri-related code contains repetitions of `(n << amt) >> amt`

I reduced some code repetitions contains `(n << amt) >> amt`.
This pull request is related to #49937.
This commit is contained in:
Mazdak Farrokhzad 2019-01-25 16:59:25 +01:00 committed by GitHub
commit ef5a5bab7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,6 +21,8 @@ use syntax::source_map;
use rustc::hir;
use rustc::mir::interpret::{sign_extend, truncate};
declare_lint! {
UNUSED_COMPARISONS,
Warn,
@ -368,14 +370,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
let (t, actually) = match ty {
ty::Int(t) => {
let ity = attr::IntType::SignedInt(t);
let bits = layout::Integer::from_attr(&cx.tcx, ity).size().bits();
let actually = (val << (128 - bits)) as i128 >> (128 - bits);
let size = layout::Integer::from_attr(&cx.tcx, ity).size();
let actually = sign_extend(val, size) as i128;
(format!("{:?}", t), actually.to_string())
}
ty::Uint(t) => {
let ity = attr::IntType::UnsignedInt(t);
let bits = layout::Integer::from_attr(&cx.tcx, ity).size().bits();
let actually = (val << (128 - bits)) >> (128 - bits);
let size = layout::Integer::from_attr(&cx.tcx, ity).size();
let actually = truncate(val, size);
(format!("{:?}", t), actually.to_string())
}
_ => bug!(),