Skip to content

Commit

Permalink
Rollup merge of rust-lang#56233 - kenta7777:kenta7777#49937, r=oli-obk
Browse files Browse the repository at this point in the history
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 rust-lang#49937.
  • Loading branch information
Centril authored Jan 25, 2019
2 parents 7187db6 + b80332e commit ef5a5ba
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/librustc_lint/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use syntax::source_map;

use rustc::hir;

use rustc::mir::interpret::{sign_extend, truncate};

declare_lint! {
UNUSED_COMPARISONS,
Warn,
Expand Down Expand Up @@ -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!(),
Expand Down

0 comments on commit ef5a5ba

Please sign in to comment.