Skip to content

Commit ef5a5ba

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#49937.
2 parents 7187db6 + b80332e commit ef5a5ba

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/librustc_lint/types.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use syntax::source_map;
2121

2222
use rustc::hir;
2323

24+
use rustc::mir::interpret::{sign_extend, truncate};
25+
2426
declare_lint! {
2527
UNUSED_COMPARISONS,
2628
Warn,
@@ -368,14 +370,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
368370
let (t, actually) = match ty {
369371
ty::Int(t) => {
370372
let ity = attr::IntType::SignedInt(t);
371-
let bits = layout::Integer::from_attr(&cx.tcx, ity).size().bits();
372-
let actually = (val << (128 - bits)) as i128 >> (128 - bits);
373+
let size = layout::Integer::from_attr(&cx.tcx, ity).size();
374+
let actually = sign_extend(val, size) as i128;
373375
(format!("{:?}", t), actually.to_string())
374376
}
375377
ty::Uint(t) => {
376378
let ity = attr::IntType::UnsignedInt(t);
377-
let bits = layout::Integer::from_attr(&cx.tcx, ity).size().bits();
378-
let actually = (val << (128 - bits)) >> (128 - bits);
379+
let size = layout::Integer::from_attr(&cx.tcx, ity).size();
380+
let actually = truncate(val, size);
379381
(format!("{:?}", t), actually.to_string())
380382
}
381383
_ => bug!(),

0 commit comments

Comments
 (0)