Reuse Integer::from_attr

This commit is contained in:
Oliver Schneider 2018-02-23 13:39:41 +01:00
parent 273025675d
commit eb18d39a04
No known key found for this signature in database
GPG key ID: A69F8D225B3AD7D9

View file

@ -23,7 +23,7 @@ use rustc::hir::map::blocks::FnLikeNode;
use rustc::middle::region; use rustc::middle::region;
use rustc::infer::InferCtxt; use rustc::infer::InferCtxt;
use rustc::ty::subst::Subst; use rustc::ty::subst::Subst;
use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::{self, Ty, TyCtxt, layout};
use rustc::ty::subst::Substs; use rustc::ty::subst::Substs;
use syntax::ast::{self, LitKind}; use syntax::ast::{self, LitKind};
use syntax::attr; use syntax::attr;
@ -153,11 +153,12 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
&self, &self,
ty: Ty, ty: Ty,
) -> u64 { ) -> u64 {
match ty.sty { let ty = match ty.sty {
ty::TyInt(ity) => ity.bit_width(), ty::TyInt(ity) => attr::IntType::SignedInt(ity),
ty::TyUint(uty) => uty.bit_width(), ty::TyUint(uty) => attr::IntType::UnsignedInt(uty),
_ => bug!("{} is not an integer", ty), _ => bug!("{} is not an integer", ty),
}.map_or(self.tcx.data_layout.pointer_size.bits(), |n| n as u64) };
layout::Integer::from_attr(self.tcx, ty).size().bits()
} }
pub fn const_eval_literal( pub fn const_eval_literal(