Skip to content

Commit eb18d39

Browse files
committed
Reuse Integer::from_attr
1 parent 2730256 commit eb18d39

File tree

1 file changed

+6
-5
lines changed
  • src/librustc_mir/hair/cx

1 file changed

+6
-5
lines changed

src/librustc_mir/hair/cx/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc::hir::map::blocks::FnLikeNode;
2323
use rustc::middle::region;
2424
use rustc::infer::InferCtxt;
2525
use rustc::ty::subst::Subst;
26-
use rustc::ty::{self, Ty, TyCtxt};
26+
use rustc::ty::{self, Ty, TyCtxt, layout};
2727
use rustc::ty::subst::Substs;
2828
use syntax::ast::{self, LitKind};
2929
use syntax::attr;
@@ -153,11 +153,12 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
153153
&self,
154154
ty: Ty,
155155
) -> u64 {
156-
match ty.sty {
157-
ty::TyInt(ity) => ity.bit_width(),
158-
ty::TyUint(uty) => uty.bit_width(),
156+
let ty = match ty.sty {
157+
ty::TyInt(ity) => attr::IntType::SignedInt(ity),
158+
ty::TyUint(uty) => attr::IntType::UnsignedInt(uty),
159159
_ => bug!("{} is not an integer", ty),
160-
}.map_or(self.tcx.data_layout.pointer_size.bits(), |n| n as u64)
160+
};
161+
layout::Integer::from_attr(self.tcx, ty).size().bits()
161162
}
162163

163164
pub fn const_eval_literal(

0 commit comments

Comments
 (0)