Skip to content

Commit

Permalink
use ImmTy::from_uint in a few more spots
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 17, 2019
1 parent 3edf099 commit 5ac2045
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/librustc_mir/transform/const_prop.rs
Expand Up @@ -19,7 +19,7 @@ use syntax_pos::{Span, DUMMY_SP};
use rustc::ty::subst::InternalSubsts;
use rustc_data_structures::indexed_vec::IndexVec;
use rustc::ty::layout::{
LayoutOf, TyLayout, LayoutError, HasTyCtxt, TargetDataLayout, HasDataLayout, Size,
LayoutOf, TyLayout, LayoutError, HasTyCtxt, TargetDataLayout, HasDataLayout,
};

use crate::interpret::{
Expand Down Expand Up @@ -396,30 +396,21 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
if let ty::Slice(_) = mplace.layout.ty.sty {
let len = mplace.meta.unwrap().to_usize(&self.ecx).unwrap();

Some(ImmTy {
imm: Immediate::Scalar(
Scalar::from_uint(
len,
Size::from_bits(
self.tcx.sess.target.usize_ty.bit_width().unwrap() as u64
)
).into(),
),
layout: self.tcx.layout_of(self.param_env.and(self.tcx.types.usize)).ok()?,
}.into())
Some(ImmTy::from_uint(
len,
self.tcx.layout_of(self.param_env.and(self.tcx.types.usize)).ok()?,
).into())
} else {
trace!("not slice: {:?}", mplace.layout.ty.sty);
None
}
},
Rvalue::NullaryOp(NullOp::SizeOf, ty) => {
type_size_of(self.tcx, self.param_env, ty).and_then(|n| Some(
ImmTy {
imm: Immediate::Scalar(
Scalar::from_uint(n, self.tcx.data_layout.pointer_size).into()
),
layout: self.tcx.layout_of(self.param_env.and(self.tcx.types.usize)).ok()?,
}.into()
ImmTy::from_uint(
n,
self.tcx.layout_of(self.param_env.and(self.tcx.types.usize)).ok()?,
).into()
))
}
Rvalue::UnaryOp(op, ref arg) => {
Expand Down

0 comments on commit 5ac2045

Please sign in to comment.