rustc: replace usize with u64 and ConstUsize.
This commit is contained in:
parent
932289c12d
commit
3ce31eb990
49 changed files with 265 additions and 274 deletions
|
|
@ -250,20 +250,15 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
|
|||
pub fn eval_length(tcx: TyCtxt,
|
||||
count: hir::BodyId,
|
||||
reason: &str)
|
||||
-> Result<usize, ErrorReported>
|
||||
-> Result<ConstUsize, ErrorReported>
|
||||
{
|
||||
let count_expr = &tcx.hir.body(count).value;
|
||||
let count_def_id = tcx.hir.body_owner_def_id(count);
|
||||
let param_env = ty::ParamEnv::empty(Reveal::UserFacing);
|
||||
let substs = Substs::identity_for_item(tcx.global_tcx(), count_def_id);
|
||||
match tcx.at(count_expr.span).const_eval(param_env.and((count_def_id, substs))) {
|
||||
Ok(&ty::Const { val: Integral(Usize(count)), .. }) => {
|
||||
let val = count.as_u64(tcx.sess.target.uint_type);
|
||||
assert_eq!(val as usize as u64, val);
|
||||
Ok(val as usize)
|
||||
},
|
||||
Ok(_) |
|
||||
Err(ConstEvalErr { kind: ErrKind::TypeckError, .. }) => Err(ErrorReported),
|
||||
Ok(&ty::Const { val: Integral(Usize(count)), .. }) => Ok(count),
|
||||
Ok(_) | Err(ConstEvalErr { kind: ErrKind::TypeckError, .. }) => Err(ErrorReported),
|
||||
Err(err) => {
|
||||
let mut diag = err.struct_error(tcx, count_expr.span, reason);
|
||||
|
||||
|
|
|
|||
|
|
@ -876,7 +876,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
|
||||
// Always promote `[T; 0]` (even when e.g. borrowed mutably).
|
||||
let promotable = match expr_ty.sty {
|
||||
ty::TyArray(_, 0) => true,
|
||||
ty::TyArray(_, len) if len.as_u64() == 0 => true,
|
||||
_ => promotable,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,8 @@ impl<'a, 'gcx, 'tcx> LvalueTy<'tcx> {
|
|||
LvalueTy::Ty {
|
||||
ty: match ty.sty {
|
||||
ty::TyArray(inner, size) => {
|
||||
tcx.mk_array(inner, size-(from as usize)-(to as usize))
|
||||
let len = size.as_u64() - (from as u64) - (to as u64);
|
||||
tcx.mk_array(inner, len)
|
||||
}
|
||||
ty::TySlice(..) => ty,
|
||||
_ => {
|
||||
|
|
@ -146,11 +147,8 @@ impl<'tcx> Rvalue<'tcx> {
|
|||
{
|
||||
match *self {
|
||||
Rvalue::Use(ref operand) => operand.ty(local_decls, tcx),
|
||||
Rvalue::Repeat(ref operand, ref count) => {
|
||||
let op_ty = operand.ty(local_decls, tcx);
|
||||
let count = count.as_u64(tcx.sess.target.uint_type);
|
||||
assert_eq!(count as usize as u64, count);
|
||||
tcx.mk_array(op_ty, count as usize)
|
||||
Rvalue::Repeat(ref operand, count) => {
|
||||
tcx.mk_array(operand.ty(local_decls, tcx), count.as_u64())
|
||||
}
|
||||
Rvalue::Ref(reg, bk, ref lv) => {
|
||||
let lv_ty = lv.ty(local_decls, tcx).to_ty(tcx);
|
||||
|
|
@ -193,7 +191,7 @@ impl<'tcx> Rvalue<'tcx> {
|
|||
Rvalue::Aggregate(ref ak, ref ops) => {
|
||||
match **ak {
|
||||
AggregateKind::Array(ty) => {
|
||||
tcx.mk_array(ty, ops.len())
|
||||
tcx.mk_array(ty, ops.len() as u64)
|
||||
}
|
||||
AggregateKind::Tuple => {
|
||||
tcx.mk_tup(
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ use std::path::PathBuf;
|
|||
|
||||
pub struct Config {
|
||||
pub target: Target,
|
||||
pub int_type: IntTy,
|
||||
pub uint_type: UintTy,
|
||||
pub isize_ty: IntTy,
|
||||
pub usize_ty: UintTy,
|
||||
}
|
||||
|
||||
#[derive(Clone, Hash, Debug)]
|
||||
|
|
@ -1149,7 +1149,7 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
|
|||
}
|
||||
};
|
||||
|
||||
let (int_type, uint_type) = match &target.target_pointer_width[..] {
|
||||
let (isize_ty, usize_ty) = match &target.target_pointer_width[..] {
|
||||
"16" => (ast::IntTy::I16, ast::UintTy::U16),
|
||||
"32" => (ast::IntTy::I32, ast::UintTy::U32),
|
||||
"64" => (ast::IntTy::I64, ast::UintTy::U64),
|
||||
|
|
@ -1159,8 +1159,8 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
|
|||
|
||||
Config {
|
||||
target,
|
||||
int_type,
|
||||
uint_type,
|
||||
isize_ty,
|
||||
usize_ty,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
|
|||
StableHasherResult};
|
||||
|
||||
use arena::{TypedArena, DroplessArena};
|
||||
use rustc_const_math::ConstUsize;
|
||||
use rustc_data_structures::indexed_vec::IndexVec;
|
||||
use std::borrow::Borrow;
|
||||
use std::cell::{Cell, RefCell};
|
||||
|
|
@ -1754,7 +1755,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
self.mk_imm_ptr(self.mk_nil())
|
||||
}
|
||||
|
||||
pub fn mk_array(self, ty: Ty<'tcx>, n: usize) -> Ty<'tcx> {
|
||||
pub fn mk_array(self, ty: Ty<'tcx>, n: u64) -> Ty<'tcx> {
|
||||
let n = ConstUsize::new(n, self.sess.target.usize_ty).unwrap();
|
||||
self.mk_ty(TyArray(ty, n))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ use syntax::ast;
|
|||
use errors::DiagnosticBuilder;
|
||||
use syntax_pos::Span;
|
||||
|
||||
use rustc_const_math::ConstUsize;
|
||||
|
||||
use hir;
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
|
@ -34,7 +36,7 @@ pub enum TypeError<'tcx> {
|
|||
AbiMismatch(ExpectedFound<abi::Abi>),
|
||||
Mutability,
|
||||
TupleSize(ExpectedFound<usize>),
|
||||
FixedArraySize(ExpectedFound<usize>),
|
||||
FixedArraySize(ExpectedFound<ConstUsize>),
|
||||
ArgCount,
|
||||
|
||||
RegionsDoesNotOutlive(Region<'tcx>, Region<'tcx>),
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
|
|||
}))
|
||||
},
|
||||
TyArray(ty, len) => {
|
||||
if len == 0 {
|
||||
if len.as_u64() == 0 {
|
||||
DefIdForest::empty()
|
||||
} else {
|
||||
ty.uninhabited_from(visited, tcx)
|
||||
|
|
|
|||
|
|
@ -837,7 +837,7 @@ impl<'a, 'tcx> Struct {
|
|||
|
||||
// Is this a fixed-size array of something non-zero
|
||||
// with at least one element?
|
||||
(_, &ty::TyArray(ety, d)) if d > 0 => {
|
||||
(_, &ty::TyArray(ety, d)) if d.as_u64() > 0 => {
|
||||
Struct::non_zero_field_paths(
|
||||
tcx,
|
||||
param_env,
|
||||
|
|
@ -1177,9 +1177,7 @@ impl<'a, 'tcx> Layout {
|
|||
ty::TyArray(element, count) => {
|
||||
let element = element.layout(tcx, param_env)?;
|
||||
let element_size = element.size(dl);
|
||||
// FIXME(eddyb) Don't use host `usize` for array lengths.
|
||||
let usize_count: usize = count;
|
||||
let count = usize_count as u64;
|
||||
let count = count.as_u64();
|
||||
if element_size.checked_mul(count, dl).is_none() {
|
||||
return Err(LayoutError::SizeOverflow(ty));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1665,11 +1665,11 @@ impl<'a, 'gcx, 'tcx> AdtDef {
|
|||
match repr_type {
|
||||
attr::UnsignedInt(ty) => {
|
||||
ConstInt::new_unsigned_truncating(discr, ty,
|
||||
tcx.sess.target.uint_type)
|
||||
tcx.sess.target.usize_ty)
|
||||
}
|
||||
attr::SignedInt(ty) => {
|
||||
ConstInt::new_signed_truncating(discr as i128, ty,
|
||||
tcx.sess.target.int_type)
|
||||
tcx.sess.target.isize_ty)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -429,7 +429,7 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
|
|||
{
|
||||
let t = relation.relate(&a_t, &b_t)?;
|
||||
if sz_a == sz_b {
|
||||
Ok(tcx.mk_array(t, sz_a))
|
||||
Ok(tcx.mk_array(t, sz_a.as_u64()))
|
||||
} else {
|
||||
Err(TypeError::FixedArraySize(expected_found(relation, &sz_a, &sz_b)))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ use syntax::ast::{self, Name};
|
|||
use syntax::symbol::keywords;
|
||||
use util::nodemap::FxHashMap;
|
||||
|
||||
use rustc_const_math::ConstUsize;
|
||||
|
||||
use serialize;
|
||||
|
||||
use hir;
|
||||
|
|
@ -110,7 +112,7 @@ pub enum TypeVariants<'tcx> {
|
|||
TyStr,
|
||||
|
||||
/// An array with the given length. Written as `[T; n]`.
|
||||
TyArray(Ty<'tcx>, usize),
|
||||
TyArray(Ty<'tcx>, ConstUsize),
|
||||
|
||||
/// The pointee of an array slice. Written as `[T]`.
|
||||
TySlice(Ty<'tcx>),
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ macro_rules! typed_literal {
|
|||
SignedInt(ast::IntTy::I32) => ConstInt::I32($lit),
|
||||
SignedInt(ast::IntTy::I64) => ConstInt::I64($lit),
|
||||
SignedInt(ast::IntTy::I128) => ConstInt::I128($lit),
|
||||
SignedInt(ast::IntTy::Is) => match $tcx.sess.target.int_type {
|
||||
SignedInt(ast::IntTy::Is) => match $tcx.sess.target.isize_ty {
|
||||
ast::IntTy::I16 => ConstInt::Isize(ConstIsize::Is16($lit)),
|
||||
ast::IntTy::I32 => ConstInt::Isize(ConstIsize::Is32($lit)),
|
||||
ast::IntTy::I64 => ConstInt::Isize(ConstIsize::Is64($lit)),
|
||||
|
|
@ -64,7 +64,7 @@ macro_rules! typed_literal {
|
|||
UnsignedInt(ast::UintTy::U32) => ConstInt::U32($lit),
|
||||
UnsignedInt(ast::UintTy::U64) => ConstInt::U64($lit),
|
||||
UnsignedInt(ast::UintTy::U128) => ConstInt::U128($lit),
|
||||
UnsignedInt(ast::UintTy::Us) => match $tcx.sess.target.uint_type {
|
||||
UnsignedInt(ast::UintTy::Us) => match $tcx.sess.target.usize_ty {
|
||||
ast::UintTy::U16 => ConstInt::Usize(ConstUsize::Us16($lit)),
|
||||
ast::UintTy::U32 => ConstInt::Usize(ConstUsize::Us32($lit)),
|
||||
ast::UintTy::U64 => ConstInt::Usize(ConstUsize::Us64($lit)),
|
||||
|
|
@ -638,7 +638,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
|
||||
pub fn const_usize(&self, val: u16) -> ConstInt {
|
||||
match self.sess.target.uint_type {
|
||||
match self.sess.target.usize_ty {
|
||||
ast::UintTy::U16 => ConstInt::Usize(ConstUsize::Us16(val as u16)),
|
||||
ast::UintTy::U32 => ConstInt::Usize(ConstUsize::Us32(val as u32)),
|
||||
ast::UintTy::U64 => ConstInt::Usize(ConstUsize::Us64(val as u64)),
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ pub enum Constructor<'tcx> {
|
|||
/// Ranges of literal values (`2...5` and `2..5`).
|
||||
ConstantRange(&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>, RangeEnd),
|
||||
/// Array patterns of length n.
|
||||
Slice(usize),
|
||||
Slice(u64),
|
||||
}
|
||||
|
||||
impl<'tcx> Constructor<'tcx> {
|
||||
|
|
@ -276,7 +276,7 @@ pub enum WitnessPreference {
|
|||
#[derive(Copy, Clone, Debug)]
|
||||
struct PatternContext<'tcx> {
|
||||
ty: Ty<'tcx>,
|
||||
max_slice_length: usize,
|
||||
max_slice_length: u64,
|
||||
}
|
||||
|
||||
/// A stack of patterns in reverse order of construction
|
||||
|
|
@ -330,8 +330,8 @@ impl<'tcx> Witness<'tcx> {
|
|||
{
|
||||
let arity = constructor_arity(cx, ctor, ty);
|
||||
let pat = {
|
||||
let len = self.0.len();
|
||||
let mut pats = self.0.drain(len-arity..).rev();
|
||||
let len = self.0.len() as u64;
|
||||
let mut pats = self.0.drain((len-arity) as usize..).rev();
|
||||
|
||||
match ty.sty {
|
||||
ty::TyAdt(..) |
|
||||
|
|
@ -423,10 +423,10 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
|||
}
|
||||
}
|
||||
ty::TyArray(ref sub_ty, length) => {
|
||||
if length > 0 && cx.is_uninhabited(sub_ty) {
|
||||
if length.as_u64() > 0 && cx.is_uninhabited(sub_ty) {
|
||||
vec![]
|
||||
} else {
|
||||
vec![Slice(length)]
|
||||
vec![Slice(length.as_u64())]
|
||||
}
|
||||
}
|
||||
ty::TyAdt(def, substs) if def.is_enum() && def.variants.len() != 1 => {
|
||||
|
|
@ -447,7 +447,7 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
|||
|
||||
fn max_slice_length<'p, 'a: 'p, 'tcx: 'a, I>(
|
||||
_cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
||||
patterns: I) -> usize
|
||||
patterns: I) -> u64
|
||||
where I: Iterator<Item=&'p Pattern<'tcx>>
|
||||
{
|
||||
// The exhaustiveness-checking paper does not include any details on
|
||||
|
|
@ -521,15 +521,15 @@ fn max_slice_length<'p, 'a: 'p, 'tcx: 'a, I>(
|
|||
for row in patterns {
|
||||
match *row.kind {
|
||||
PatternKind::Constant { value: &ty::Const { val: ConstVal::ByteStr(b), .. } } => {
|
||||
max_fixed_len = cmp::max(max_fixed_len, b.data.len());
|
||||
max_fixed_len = cmp::max(max_fixed_len, b.data.len() as u64);
|
||||
}
|
||||
PatternKind::Slice { ref prefix, slice: None, ref suffix } => {
|
||||
let fixed_len = prefix.len() + suffix.len();
|
||||
let fixed_len = prefix.len() as u64 + suffix.len() as u64;
|
||||
max_fixed_len = cmp::max(max_fixed_len, fixed_len);
|
||||
}
|
||||
PatternKind::Slice { ref prefix, slice: Some(_), ref suffix } => {
|
||||
max_prefix_len = cmp::max(max_prefix_len, prefix.len());
|
||||
max_suffix_len = cmp::max(max_suffix_len, suffix.len());
|
||||
max_prefix_len = cmp::max(max_prefix_len, prefix.len() as u64);
|
||||
max_suffix_len = cmp::max(max_suffix_len, suffix.len() as u64);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
@ -729,11 +729,11 @@ fn pat_constructors<'tcx>(_cx: &mut MatchCheckCtxt,
|
|||
PatternKind::Range { lo, hi, end } =>
|
||||
Some(vec![ConstantRange(lo, hi, end)]),
|
||||
PatternKind::Array { .. } => match pcx.ty.sty {
|
||||
ty::TyArray(_, length) => Some(vec![Slice(length)]),
|
||||
ty::TyArray(_, length) => Some(vec![Slice(length.as_u64())]),
|
||||
_ => span_bug!(pat.span, "bad ty {:?} for array pattern", pcx.ty)
|
||||
},
|
||||
PatternKind::Slice { ref prefix, ref slice, ref suffix } => {
|
||||
let pat_len = prefix.len() + suffix.len();
|
||||
let pat_len = prefix.len() as u64 + suffix.len() as u64;
|
||||
if slice.is_some() {
|
||||
Some((pat_len..pcx.max_slice_length+1).map(Slice).collect())
|
||||
} else {
|
||||
|
|
@ -748,10 +748,10 @@ fn pat_constructors<'tcx>(_cx: &mut MatchCheckCtxt,
|
|||
///
|
||||
/// For instance, a tuple pattern (_, 42, Some([])) has the arity of 3.
|
||||
/// A struct pattern's arity is the number of fields it contains, etc.
|
||||
fn constructor_arity(_cx: &MatchCheckCtxt, ctor: &Constructor, ty: Ty) -> usize {
|
||||
fn constructor_arity(_cx: &MatchCheckCtxt, ctor: &Constructor, ty: Ty) -> u64 {
|
||||
debug!("constructor_arity({:?}, {:?})", ctor, ty);
|
||||
match ty.sty {
|
||||
ty::TyTuple(ref fs, _) => fs.len(),
|
||||
ty::TyTuple(ref fs, _) => fs.len() as u64,
|
||||
ty::TySlice(..) | ty::TyArray(..) => match *ctor {
|
||||
Slice(length) => length,
|
||||
ConstantValue(_) => 0,
|
||||
|
|
@ -759,7 +759,7 @@ fn constructor_arity(_cx: &MatchCheckCtxt, ctor: &Constructor, ty: Ty) -> usize
|
|||
},
|
||||
ty::TyRef(..) => 1,
|
||||
ty::TyAdt(adt, _) => {
|
||||
adt.variants[ctor.variant_index_for_adt(adt)].fields.len()
|
||||
adt.variants[ctor.variant_index_for_adt(adt)].fields.len() as u64
|
||||
}
|
||||
_ => 0
|
||||
}
|
||||
|
|
@ -777,7 +777,7 @@ fn constructor_sub_pattern_tys<'a, 'tcx: 'a>(cx: &MatchCheckCtxt<'a, 'tcx>,
|
|||
match ty.sty {
|
||||
ty::TyTuple(ref fs, _) => fs.into_iter().map(|t| *t).collect(),
|
||||
ty::TySlice(ty) | ty::TyArray(ty, _) => match *ctor {
|
||||
Slice(length) => repeat(ty).take(length).collect(),
|
||||
Slice(length) => (0..length).map(|_| ty).collect(),
|
||||
ConstantValue(_) => vec![],
|
||||
_ => bug!("bad slice pattern {:?} {:?}", ctor, ty)
|
||||
},
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
|
|||
},
|
||||
(&LitKind::Int(n, _), &ty::TyInt(IntTy::Is)) |
|
||||
(&LitKind::Int(n, Signed(IntTy::Is)), _) => {
|
||||
match tcx.sess.target.int_type {
|
||||
match tcx.sess.target.isize_ty {
|
||||
IntTy::I16 => if n == I16_OVERFLOW {
|
||||
Some(Isize(Is16(i16::min_value())))
|
||||
} else {
|
||||
|
|
@ -342,12 +342,12 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
|
|||
"size_of" => {
|
||||
let size = layout_of(substs.type_at(0))?.size(tcx).bytes();
|
||||
return Ok(mk_const(Integral(Usize(ConstUsize::new(size,
|
||||
tcx.sess.target.uint_type).unwrap()))));
|
||||
tcx.sess.target.usize_ty).unwrap()))));
|
||||
}
|
||||
"min_align_of" => {
|
||||
let align = layout_of(substs.type_at(0))?.align(tcx).abi();
|
||||
return Ok(mk_const(Integral(Usize(ConstUsize::new(align,
|
||||
tcx.sess.target.uint_type).unwrap()))));
|
||||
tcx.sess.target.usize_ty).unwrap()))));
|
||||
}
|
||||
_ => signal!(e, TypeckError)
|
||||
}
|
||||
|
|
@ -421,7 +421,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
|
|||
}
|
||||
let arr = cx.eval(arr)?;
|
||||
let idx = match cx.eval(idx)?.val {
|
||||
Integral(Usize(i)) => i.as_u64(tcx.sess.target.uint_type),
|
||||
Integral(Usize(i)) => i.as_u64(),
|
||||
_ => signal!(idx, IndexNotUsize),
|
||||
};
|
||||
assert_eq!(idx as usize as u64, idx);
|
||||
|
|
@ -431,7 +431,6 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
|
|||
elem
|
||||
} else {
|
||||
let n = v.len() as u64;
|
||||
assert_eq!(n as usize as u64, n);
|
||||
signal!(e, IndexOutOfBounds { len: n, index: idx })
|
||||
}
|
||||
}
|
||||
|
|
@ -457,7 +456,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
|
|||
}
|
||||
hir::ExprRepeat(ref elem, _) => {
|
||||
let n = match ty.sty {
|
||||
ty::TyArray(_, n) => n as u64,
|
||||
ty::TyArray(_, n) => n.as_u64(),
|
||||
_ => span_bug!(e.span, "typeck error")
|
||||
};
|
||||
mk_const(Aggregate(Repeat(cx.eval(elem)?, n)))
|
||||
|
|
@ -562,7 +561,7 @@ fn cast_const_int<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
ty::TyInt(ast::IntTy::I64) => Ok(Integral(I64(v as i128 as i64))),
|
||||
ty::TyInt(ast::IntTy::I128) => Ok(Integral(I128(v as i128))),
|
||||
ty::TyInt(ast::IntTy::Is) => {
|
||||
Ok(Integral(Isize(ConstIsize::new_truncating(v as i128, tcx.sess.target.int_type))))
|
||||
Ok(Integral(Isize(ConstIsize::new_truncating(v as i128, tcx.sess.target.isize_ty))))
|
||||
},
|
||||
ty::TyUint(ast::UintTy::U8) => Ok(Integral(U8(v as u8))),
|
||||
ty::TyUint(ast::UintTy::U16) => Ok(Integral(U16(v as u16))),
|
||||
|
|
@ -570,7 +569,7 @@ fn cast_const_int<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
ty::TyUint(ast::UintTy::U64) => Ok(Integral(U64(v as u64))),
|
||||
ty::TyUint(ast::UintTy::U128) => Ok(Integral(U128(v as u128))),
|
||||
ty::TyUint(ast::UintTy::Us) => {
|
||||
Ok(Integral(Usize(ConstUsize::new_truncating(v, tcx.sess.target.uint_type))))
|
||||
Ok(Integral(Usize(ConstUsize::new_truncating(v, tcx.sess.target.usize_ty))))
|
||||
},
|
||||
ty::TyFloat(fty) => {
|
||||
if let Some(i) = val.to_u128() {
|
||||
|
|
@ -636,7 +635,9 @@ fn cast_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
Err(ErrKind::UnimplementedConstVal("casting a bytestr to a raw ptr"))
|
||||
},
|
||||
ty::TyRef(_, ty::TypeAndMut { ref ty, mutbl: hir::MutImmutable }) => match ty.sty {
|
||||
ty::TyArray(ty, n) if ty == tcx.types.u8 && n == b.data.len() => Ok(val),
|
||||
ty::TyArray(ty, n) if ty == tcx.types.u8 && n.as_u64() == b.data.len() as u64 => {
|
||||
Ok(val)
|
||||
}
|
||||
ty::TySlice(_) => {
|
||||
Err(ErrKind::UnimplementedConstVal("casting a bytestr to slice"))
|
||||
},
|
||||
|
|
@ -678,12 +679,12 @@ fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind,
|
|||
(&ty::TyInt(ity), _) |
|
||||
(_, Signed(ity)) => {
|
||||
Ok(Integral(ConstInt::new_signed_truncating(n as i128,
|
||||
ity, tcx.sess.target.int_type)))
|
||||
ity, tcx.sess.target.isize_ty)))
|
||||
}
|
||||
(&ty::TyUint(uty), _) |
|
||||
(_, Unsigned(uty)) => {
|
||||
Ok(Integral(ConstInt::new_unsigned_truncating(n as u128,
|
||||
uty, tcx.sess.target.uint_type)))
|
||||
uty, tcx.sess.target.usize_ty)))
|
||||
}
|
||||
_ => bug!()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -537,7 +537,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
|||
|
||||
ty::TyArray(_, len) => {
|
||||
// fixed-length array
|
||||
assert!(len >= prefix.len() + suffix.len());
|
||||
assert!(len.as_u64() >= prefix.len() as u64 + suffix.len() as u64);
|
||||
PatternKind::Array { prefix: prefix, slice: slice, suffix: suffix }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -311,17 +311,13 @@ impl ::std::fmt::Display for ConstInt {
|
|||
I32(i) => write!(fmt, "{}i32", i),
|
||||
I64(i) => write!(fmt, "{}i64", i),
|
||||
I128(i) => write!(fmt, "{}i128", i),
|
||||
Isize(ConstIsize::Is64(i)) => write!(fmt, "{}isize", i),
|
||||
Isize(ConstIsize::Is32(i)) => write!(fmt, "{}isize", i),
|
||||
Isize(ConstIsize::Is16(i)) => write!(fmt, "{}isize", i),
|
||||
Isize(i) => write!(fmt, "{}isize", i),
|
||||
U8(i) => write!(fmt, "{}u8", i),
|
||||
U16(i) => write!(fmt, "{}u16", i),
|
||||
U32(i) => write!(fmt, "{}u32", i),
|
||||
U64(i) => write!(fmt, "{}u64", i),
|
||||
U128(i) => write!(fmt, "{}u128", i),
|
||||
Usize(ConstUsize::Us64(i)) => write!(fmt, "{}usize", i),
|
||||
Usize(ConstUsize::Us32(i)) => write!(fmt, "{}usize", i),
|
||||
Usize(ConstUsize::Us16(i)) => write!(fmt, "{}usize", i),
|
||||
Usize(i) => write!(fmt, "{}usize", i),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,18 +21,22 @@ pub enum ConstIsize {
|
|||
}
|
||||
pub use self::ConstIsize::*;
|
||||
|
||||
impl ::std::fmt::Display for ConstIsize {
|
||||
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
|
||||
write!(fmt, "{}", self.as_i64())
|
||||
}
|
||||
}
|
||||
|
||||
impl ConstIsize {
|
||||
pub fn as_i64(self, target_int_ty: ast::IntTy) -> i64 {
|
||||
match (self, target_int_ty) {
|
||||
(Is16(i), ast::IntTy::I16) => i as i64,
|
||||
(Is32(i), ast::IntTy::I32) => i as i64,
|
||||
(Is64(i), ast::IntTy::I64) => i,
|
||||
_ => panic!("unable to convert self ({:?}) to target isize ({:?})",
|
||||
self, target_int_ty),
|
||||
pub fn as_i64(self) -> i64 {
|
||||
match self {
|
||||
Is16(i) => i as i64,
|
||||
Is32(i) => i as i64,
|
||||
Is64(i) => i,
|
||||
}
|
||||
}
|
||||
pub fn new(i: i64, target_int_ty: ast::IntTy) -> Result<Self, ConstMathErr> {
|
||||
match target_int_ty {
|
||||
pub fn new(i: i64, isize_ty: ast::IntTy) -> Result<Self, ConstMathErr> {
|
||||
match isize_ty {
|
||||
ast::IntTy::I16 if i as i16 as i64 == i => Ok(Is16(i as i16)),
|
||||
ast::IntTy::I16 => Err(LitOutOfRange(ast::IntTy::Is)),
|
||||
ast::IntTy::I32 if i as i32 as i64 == i => Ok(Is32(i as i32)),
|
||||
|
|
@ -41,8 +45,8 @@ impl ConstIsize {
|
|||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
pub fn new_truncating(i: i128, target_int_ty: ast::IntTy) -> Self {
|
||||
match target_int_ty {
|
||||
pub fn new_truncating(i: i128, isize_ty: ast::IntTy) -> Self {
|
||||
match isize_ty {
|
||||
ast::IntTy::I16 => Is16(i as i16),
|
||||
ast::IntTy::I32 => Is32(i as i32),
|
||||
ast::IntTy::I64 => Is64(i as i64),
|
||||
|
|
|
|||
|
|
@ -21,18 +21,22 @@ pub enum ConstUsize {
|
|||
}
|
||||
pub use self::ConstUsize::*;
|
||||
|
||||
impl ::std::fmt::Display for ConstUsize {
|
||||
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
|
||||
write!(fmt, "{}", self.as_u64())
|
||||
}
|
||||
}
|
||||
|
||||
impl ConstUsize {
|
||||
pub fn as_u64(self, target_uint_ty: ast::UintTy) -> u64 {
|
||||
match (self, target_uint_ty) {
|
||||
(Us16(i), ast::UintTy::U16) => i as u64,
|
||||
(Us32(i), ast::UintTy::U32) => i as u64,
|
||||
(Us64(i), ast::UintTy::U64) => i,
|
||||
_ => panic!("unable to convert self ({:?}) to target usize ({:?})",
|
||||
self, target_uint_ty),
|
||||
pub fn as_u64(self) -> u64 {
|
||||
match self {
|
||||
Us16(i) => i as u64,
|
||||
Us32(i) => i as u64,
|
||||
Us64(i) => i,
|
||||
}
|
||||
}
|
||||
pub fn new(i: u64, target_uint_ty: ast::UintTy) -> Result<Self, ConstMathErr> {
|
||||
match target_uint_ty {
|
||||
pub fn new(i: u64, usize_ty: ast::UintTy) -> Result<Self, ConstMathErr> {
|
||||
match usize_ty {
|
||||
ast::UintTy::U16 if i as u16 as u64 == i => Ok(Us16(i as u16)),
|
||||
ast::UintTy::U16 => Err(ULitOutOfRange(ast::UintTy::Us)),
|
||||
ast::UintTy::U32 if i as u32 as u64 == i => Ok(Us32(i as u32)),
|
||||
|
|
@ -41,8 +45,8 @@ impl ConstUsize {
|
|||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
pub fn new_truncating(i: u128, target_uint_ty: ast::UintTy) -> Self {
|
||||
match target_uint_ty {
|
||||
pub fn new_truncating(i: u128, usize_ty: ast::UintTy) -> Self {
|
||||
match usize_ty {
|
||||
ast::UintTy::U16 => Us16(i as u16),
|
||||
ast::UintTy::U32 => Us32(i as u32),
|
||||
ast::UintTy::U64 => Us64(i as u64),
|
||||
|
|
|
|||
|
|
@ -801,13 +801,13 @@ fn walk_ty() {
|
|||
test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
|
||||
let tcx = env.infcx.tcx;
|
||||
let int_ty = tcx.types.isize;
|
||||
let uint_ty = tcx.types.usize;
|
||||
let tup1_ty = tcx.intern_tup(&[int_ty, uint_ty, int_ty, uint_ty], false);
|
||||
let tup2_ty = tcx.intern_tup(&[tup1_ty, tup1_ty, uint_ty], false);
|
||||
let usize_ty = tcx.types.usize;
|
||||
let tup1_ty = tcx.intern_tup(&[int_ty, usize_ty, int_ty, usize_ty], false);
|
||||
let tup2_ty = tcx.intern_tup(&[tup1_ty, tup1_ty, usize_ty], false);
|
||||
let walked: Vec<_> = tup2_ty.walk().collect();
|
||||
assert_eq!(walked,
|
||||
[tup2_ty, tup1_ty, int_ty, uint_ty, int_ty, uint_ty, tup1_ty, int_ty,
|
||||
uint_ty, int_ty, uint_ty, uint_ty]);
|
||||
[tup2_ty, tup1_ty, int_ty, usize_ty, int_ty, usize_ty, tup1_ty, int_ty,
|
||||
usize_ty, int_ty, usize_ty, usize_ty]);
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -816,20 +816,20 @@ fn walk_ty_skip_subtree() {
|
|||
test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
|
||||
let tcx = env.infcx.tcx;
|
||||
let int_ty = tcx.types.isize;
|
||||
let uint_ty = tcx.types.usize;
|
||||
let tup1_ty = tcx.intern_tup(&[int_ty, uint_ty, int_ty, uint_ty], false);
|
||||
let tup2_ty = tcx.intern_tup(&[tup1_ty, tup1_ty, uint_ty], false);
|
||||
let usize_ty = tcx.types.usize;
|
||||
let tup1_ty = tcx.intern_tup(&[int_ty, usize_ty, int_ty, usize_ty], false);
|
||||
let tup2_ty = tcx.intern_tup(&[tup1_ty, tup1_ty, usize_ty], false);
|
||||
|
||||
// types we expect to see (in order), plus a boolean saying
|
||||
// whether to skip the subtree.
|
||||
let mut expected = vec![(tup2_ty, false),
|
||||
(tup1_ty, false),
|
||||
(int_ty, false),
|
||||
(uint_ty, false),
|
||||
(usize_ty, false),
|
||||
(int_ty, false),
|
||||
(uint_ty, false),
|
||||
(usize_ty, false),
|
||||
(tup1_ty, true), // skip the isize/usize/isize/usize
|
||||
(uint_ty, false)];
|
||||
(usize_ty, false)];
|
||||
expected.reverse();
|
||||
|
||||
let mut walker = tup2_ty.walk();
|
||||
|
|
|
|||
|
|
@ -93,8 +93,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
|
|||
|
||||
if binop.node.is_shift() {
|
||||
let opt_ty_bits = match cx.tables.node_id_to_type(l.hir_id).sty {
|
||||
ty::TyInt(t) => Some(int_ty_bits(t, cx.sess().target.int_type)),
|
||||
ty::TyUint(t) => Some(uint_ty_bits(t, cx.sess().target.uint_type)),
|
||||
ty::TyInt(t) => Some(int_ty_bits(t, cx.sess().target.isize_ty)),
|
||||
ty::TyUint(t) => Some(uint_ty_bits(t, cx.sess().target.usize_ty)),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
|
@ -141,7 +141,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
|
|||
ast::LitKind::Int(v, ast::LitIntType::Signed(_)) |
|
||||
ast::LitKind::Int(v, ast::LitIntType::Unsuffixed) => {
|
||||
let int_type = if let ast::IntTy::Is = t {
|
||||
cx.sess().target.int_type
|
||||
cx.sess().target.isize_ty
|
||||
} else {
|
||||
t
|
||||
};
|
||||
|
|
@ -164,7 +164,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
|
|||
}
|
||||
ty::TyUint(t) => {
|
||||
let uint_type = if let ast::UintTy::Us = t {
|
||||
cx.sess().target.uint_type
|
||||
cx.sess().target.usize_ty
|
||||
} else {
|
||||
t
|
||||
};
|
||||
|
|
@ -250,9 +250,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
|
|||
}
|
||||
}
|
||||
|
||||
fn int_ty_bits(int_ty: ast::IntTy, target_int_ty: ast::IntTy) -> u64 {
|
||||
fn int_ty_bits(int_ty: ast::IntTy, isize_ty: ast::IntTy) -> u64 {
|
||||
match int_ty {
|
||||
ast::IntTy::Is => int_ty_bits(target_int_ty, target_int_ty),
|
||||
ast::IntTy::Is => int_ty_bits(isize_ty, isize_ty),
|
||||
ast::IntTy::I8 => 8,
|
||||
ast::IntTy::I16 => 16 as u64,
|
||||
ast::IntTy::I32 => 32,
|
||||
|
|
@ -261,9 +261,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
|
|||
}
|
||||
}
|
||||
|
||||
fn uint_ty_bits(uint_ty: ast::UintTy, target_uint_ty: ast::UintTy) -> u64 {
|
||||
fn uint_ty_bits(uint_ty: ast::UintTy, usize_ty: ast::UintTy) -> u64 {
|
||||
match uint_ty {
|
||||
ast::UintTy::Us => uint_ty_bits(target_uint_ty, target_uint_ty),
|
||||
ast::UintTy::Us => uint_ty_bits(usize_ty, usize_ty),
|
||||
ast::UintTy::U8 => 8,
|
||||
ast::UintTy::U16 => 16,
|
||||
ast::UintTy::U32 => 32,
|
||||
|
|
|
|||
|
|
@ -388,7 +388,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
ast::IntTy::I64 => ConstInt::I64(-1),
|
||||
ast::IntTy::I128 => ConstInt::I128(-1),
|
||||
ast::IntTy::Is => {
|
||||
let int_ty = self.hir.tcx().sess.target.int_type;
|
||||
let int_ty = self.hir.tcx().sess.target.isize_ty;
|
||||
let val = ConstIsize::new(-1, int_ty).unwrap();
|
||||
ConstInt::Isize(val)
|
||||
}
|
||||
|
|
@ -420,7 +420,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
ast::IntTy::I64 => ConstInt::I64(i64::min_value()),
|
||||
ast::IntTy::I128 => ConstInt::I128(i128::min_value()),
|
||||
ast::IntTy::Is => {
|
||||
let int_ty = self.hir.tcx().sess.target.int_type;
|
||||
let int_ty = self.hir.tcx().sess.target.isize_ty;
|
||||
let min = match int_ty {
|
||||
ast::IntTy::I16 => std::i16::MIN as i64,
|
||||
ast::IntTy::I32 => std::i32::MIN as i64,
|
||||
|
|
|
|||
|
|
@ -279,7 +279,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
|
||||
assert!(ty.is_slice());
|
||||
|
||||
let array_ty = tcx.mk_array(tcx.types.u8, bytes.data.len());
|
||||
let array_ty = tcx.mk_array(tcx.types.u8, bytes.data.len() as u64);
|
||||
let array_ref = tcx.mk_imm_ref(tcx.types.re_static, array_ty);
|
||||
let array = self.literal_operand(test.span, array_ref, Literal::Value {
|
||||
value
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
ast::UintTy::U64 => ConstInt::U64(0),
|
||||
ast::UintTy::U128 => ConstInt::U128(0),
|
||||
ast::UintTy::Us => {
|
||||
let uint_ty = self.hir.tcx().sess.target.uint_type;
|
||||
let uint_ty = self.hir.tcx().sess.target.usize_ty;
|
||||
let val = ConstUsize::new(0, uint_ty).unwrap();
|
||||
ConstInt::Usize(val)
|
||||
}
|
||||
|
|
@ -96,7 +96,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
ast::IntTy::I64 => ConstInt::I64(0),
|
||||
ast::IntTy::I128 => ConstInt::I128(0),
|
||||
ast::IntTy::Is => {
|
||||
let int_ty = self.hir.tcx().sess.target.int_type;
|
||||
let int_ty = self.hir.tcx().sess.target.isize_ty;
|
||||
let val = ConstIsize::new(0, int_ty).unwrap();
|
||||
ConstInt::Isize(val)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
|
||||
pub fn usize_literal(&mut self, value: u64) -> Literal<'tcx> {
|
||||
match ConstUsize::new(value, self.tcx.sess.target.uint_type) {
|
||||
match ConstUsize::new(value, self.tcx.sess.target.usize_ty) {
|
||||
Ok(val) => {
|
||||
Literal::Value {
|
||||
value: self.tcx.mk_const(ty::Const {
|
||||
|
|
|
|||
|
|
@ -292,7 +292,7 @@ fn build_clone_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
|
|||
|
||||
match self_ty.sty {
|
||||
_ if is_copy => builder.copy_shim(),
|
||||
ty::TyArray(ty, len) => builder.array_shim(ty, len),
|
||||
ty::TyArray(ty, len) => builder.array_shim(ty, len.as_u64()),
|
||||
ty::TyTuple(tys, _) => builder.tuple_shim(tys),
|
||||
_ => {
|
||||
bug!("clone shim for `{:?}` which is not `Copy` and is not an aggregate", self_ty);
|
||||
|
|
@ -470,8 +470,8 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
|
|||
);
|
||||
}
|
||||
|
||||
fn make_usize(&self, value: usize) -> Box<Constant<'tcx>> {
|
||||
let value = ConstUsize::new(value as u64, self.tcx.sess.target.uint_type).unwrap();
|
||||
fn make_usize(&self, value: u64) -> Box<Constant<'tcx>> {
|
||||
let value = ConstUsize::new(value, self.tcx.sess.target.usize_ty).unwrap();
|
||||
box Constant {
|
||||
span: self.span,
|
||||
ty: self.tcx.types.usize,
|
||||
|
|
@ -484,7 +484,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn array_shim(&mut self, ty: ty::Ty<'tcx>, len: usize) {
|
||||
fn array_shim(&mut self, ty: ty::Ty<'tcx>, len: u64) {
|
||||
let tcx = self.tcx;
|
||||
let span = self.span;
|
||||
let rcvr = Lvalue::Local(Local::new(1+0)).deref();
|
||||
|
|
|
|||
|
|
@ -695,8 +695,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
|
|||
}
|
||||
_ => false
|
||||
}
|
||||
} else if let ty::TyArray(_, 0) = ty.sty {
|
||||
self.mode == Mode::Fn
|
||||
} else if let ty::TyArray(_, len) = ty.sty {
|
||||
len.as_u64() == 0 && self.mode == Mode::Fn
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
|
|
|||
|
|
@ -209,7 +209,8 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
|
|||
LvalueTy::Ty {
|
||||
ty: match base_ty.sty {
|
||||
ty::TyArray(inner, size) => {
|
||||
let min_size = (from as usize) + (to as usize);
|
||||
let size = size.as_u64();
|
||||
let min_size = (from as u64) + (to as u64);
|
||||
if let Some(rest_size) = size.checked_sub(min_size) {
|
||||
tcx.mk_array(inner, rest_size)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
use llvm::{self, ValueRef, AttributePlace};
|
||||
use base;
|
||||
use builder::Builder;
|
||||
use common::{instance_ty, ty_fn_sig, type_is_fat_ptr, C_uint};
|
||||
use common::{instance_ty, ty_fn_sig, type_is_fat_ptr, C_usize};
|
||||
use context::CrateContext;
|
||||
use cabi_x86;
|
||||
use cabi_x86_64;
|
||||
|
|
@ -527,7 +527,7 @@ impl<'a, 'tcx> ArgType<'tcx> {
|
|||
}
|
||||
let ccx = bcx.ccx;
|
||||
if self.is_indirect() {
|
||||
let llsz = C_uint(ccx, self.layout.size(ccx).bytes());
|
||||
let llsz = C_usize(ccx, self.layout.size(ccx).bytes());
|
||||
let llalign = self.layout.align(ccx).abi();
|
||||
base::call_memcpy(bcx, dst, val, llsz, llalign as u32);
|
||||
} else if let Some(ty) = self.cast {
|
||||
|
|
@ -564,7 +564,7 @@ impl<'a, 'tcx> ArgType<'tcx> {
|
|||
base::call_memcpy(bcx,
|
||||
bcx.pointercast(dst, Type::i8p(ccx)),
|
||||
bcx.pointercast(llscratch, Type::i8p(ccx)),
|
||||
C_uint(ccx, self.layout.size(ccx).bytes()),
|
||||
C_usize(ccx, self.layout.size(ccx).bytes()),
|
||||
cmp::min(self.layout.align(ccx).abi() as u32,
|
||||
llalign_of_min(ccx, ty)));
|
||||
|
||||
|
|
|
|||
|
|
@ -397,11 +397,11 @@ pub fn trans_set_discr<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, val: Valu
|
|||
match *l {
|
||||
layout::CEnum{ discr, min, max, .. } => {
|
||||
assert_discr_in_range(min, max, to);
|
||||
bcx.store(C_integral(Type::from_integer(bcx.ccx, discr), to, true),
|
||||
bcx.store(C_int(Type::from_integer(bcx.ccx, discr), to as i64),
|
||||
val, None);
|
||||
}
|
||||
layout::General{ discr, .. } => {
|
||||
bcx.store(C_integral(Type::from_integer(bcx.ccx, discr), to, true),
|
||||
bcx.store(C_int(Type::from_integer(bcx.ccx, discr), to as i64),
|
||||
bcx.struct_gep(val, 0), None);
|
||||
}
|
||||
layout::Univariant { .. }
|
||||
|
|
@ -423,7 +423,7 @@ pub fn trans_set_discr<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, val: Valu
|
|||
// than storing null to single target field.
|
||||
let llptr = bcx.pointercast(val, Type::i8(bcx.ccx).ptr_to());
|
||||
let fill_byte = C_u8(bcx.ccx, 0);
|
||||
let size = C_uint(bcx.ccx, nonnull.stride().bytes());
|
||||
let size = C_usize(bcx.ccx, nonnull.stride().bytes());
|
||||
let align = C_i32(bcx.ccx, nonnull.align.abi() as i32);
|
||||
base::call_memset(bcx, llptr, fill_byte, size, align, false);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ use mir::lvalue::LvalueRef;
|
|||
use attributes;
|
||||
use builder::Builder;
|
||||
use callee;
|
||||
use common::{C_bool, C_bytes_in_context, C_i32, C_uint};
|
||||
use common::{C_bool, C_bytes_in_context, C_i32, C_usize};
|
||||
use collector::{self, TransItemCollectionMode};
|
||||
use common::{C_struct_in_context, C_u64, C_undef, C_array};
|
||||
use common::CrateContext;
|
||||
|
|
@ -201,7 +201,7 @@ pub fn unsized_info<'ccx, 'tcx>(ccx: &CrateContext<'ccx, 'tcx>,
|
|||
-> ValueRef {
|
||||
let (source, target) = ccx.tcx().struct_lockstep_tails(source, target);
|
||||
match (&source.sty, &target.sty) {
|
||||
(&ty::TyArray(_, len), &ty::TySlice(_)) => C_uint(ccx, len),
|
||||
(&ty::TyArray(_, len), &ty::TySlice(_)) => C_usize(ccx, len.as_u64()),
|
||||
(&ty::TyDynamic(..), &ty::TyDynamic(..)) => {
|
||||
// For now, upcasts are limited to changes in marker
|
||||
// traits, and hence never actually require an actual
|
||||
|
|
@ -524,7 +524,7 @@ pub fn call_memcpy<'a, 'tcx>(b: &Builder<'a, 'tcx>,
|
|||
let memcpy = ccx.get_intrinsic(&key);
|
||||
let src_ptr = b.pointercast(src, Type::i8p(ccx));
|
||||
let dst_ptr = b.pointercast(dst, Type::i8p(ccx));
|
||||
let size = b.intcast(n_bytes, ccx.int_type(), false);
|
||||
let size = b.intcast(n_bytes, ccx.isize_ty(), false);
|
||||
let align = C_i32(ccx, align as i32);
|
||||
let volatile = C_bool(ccx, false);
|
||||
b.call(memcpy, &[dst_ptr, src_ptr, size, align, volatile], None);
|
||||
|
|
@ -545,7 +545,7 @@ pub fn memcpy_ty<'a, 'tcx>(
|
|||
}
|
||||
|
||||
let align = align.unwrap_or_else(|| ccx.align_of(t));
|
||||
call_memcpy(bcx, dst, src, C_uint(ccx, size), align);
|
||||
call_memcpy(bcx, dst, src, C_usize(ccx, size), align);
|
||||
}
|
||||
|
||||
pub fn call_memset<'a, 'tcx>(b: &Builder<'a, 'tcx>,
|
||||
|
|
@ -696,7 +696,7 @@ fn maybe_create_entry_wrapper(ccx: &CrateContext) {
|
|||
sp: Span,
|
||||
rust_main: ValueRef,
|
||||
use_start_lang_item: bool) {
|
||||
let llfty = Type::func(&[ccx.int_type(), Type::i8p(ccx).ptr_to()], &ccx.int_type());
|
||||
let llfty = Type::func(&[ccx.isize_ty(), Type::i8p(ccx).ptr_to()], &ccx.isize_ty());
|
||||
|
||||
if declare::get_defined_value(ccx, "main").is_some() {
|
||||
// FIXME: We should be smart and show a better diagnostic here.
|
||||
|
|
|
|||
|
|
@ -221,9 +221,15 @@ pub fn C_undef(t: Type) -> ValueRef {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn C_integral(t: Type, u: u64, sign_extend: bool) -> ValueRef {
|
||||
pub fn C_int(t: Type, i: i64) -> ValueRef {
|
||||
unsafe {
|
||||
llvm::LLVMConstInt(t.to_ref(), u, sign_extend as Bool)
|
||||
llvm::LLVMConstInt(t.to_ref(), i as u64, True)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn C_uint(t: Type, i: u64) -> ValueRef {
|
||||
unsafe {
|
||||
llvm::LLVMConstInt(t.to_ref(), i, False)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -239,49 +245,34 @@ pub fn C_nil(ccx: &CrateContext) -> ValueRef {
|
|||
}
|
||||
|
||||
pub fn C_bool(ccx: &CrateContext, val: bool) -> ValueRef {
|
||||
C_integral(Type::i1(ccx), val as u64, false)
|
||||
C_uint(Type::i1(ccx), val as u64)
|
||||
}
|
||||
|
||||
pub fn C_i32(ccx: &CrateContext, i: i32) -> ValueRef {
|
||||
C_integral(Type::i32(ccx), i as u64, true)
|
||||
C_int(Type::i32(ccx), i as i64)
|
||||
}
|
||||
|
||||
pub fn C_u32(ccx: &CrateContext, i: u32) -> ValueRef {
|
||||
C_integral(Type::i32(ccx), i as u64, false)
|
||||
C_uint(Type::i32(ccx), i as u64)
|
||||
}
|
||||
|
||||
pub fn C_u64(ccx: &CrateContext, i: u64) -> ValueRef {
|
||||
C_integral(Type::i64(ccx), i, false)
|
||||
C_uint(Type::i64(ccx), i)
|
||||
}
|
||||
|
||||
pub fn C_uint<I: AsU64>(ccx: &CrateContext, i: I) -> ValueRef {
|
||||
let v = i.as_u64();
|
||||
|
||||
let bit_size = machine::llbitsize_of_real(ccx, ccx.int_type());
|
||||
pub fn C_usize(ccx: &CrateContext, i: u64) -> ValueRef {
|
||||
let bit_size = machine::llbitsize_of_real(ccx, ccx.isize_ty());
|
||||
|
||||
if bit_size < 64 {
|
||||
// make sure it doesn't overflow
|
||||
assert!(v < (1<<bit_size));
|
||||
assert!(i < (1<<bit_size));
|
||||
}
|
||||
|
||||
C_integral(ccx.int_type(), v, false)
|
||||
C_uint(ccx.isize_ty(), i)
|
||||
}
|
||||
|
||||
pub trait AsI64 { fn as_i64(self) -> i64; }
|
||||
pub trait AsU64 { fn as_u64(self) -> u64; }
|
||||
|
||||
// FIXME: remove the intptr conversions, because they
|
||||
// are host-architecture-dependent
|
||||
impl AsI64 for i64 { fn as_i64(self) -> i64 { self as i64 }}
|
||||
impl AsI64 for i32 { fn as_i64(self) -> i64 { self as i64 }}
|
||||
impl AsI64 for isize { fn as_i64(self) -> i64 { self as i64 }}
|
||||
|
||||
impl AsU64 for u64 { fn as_u64(self) -> u64 { self as u64 }}
|
||||
impl AsU64 for u32 { fn as_u64(self) -> u64 { self as u64 }}
|
||||
impl AsU64 for usize { fn as_u64(self) -> u64 { self as u64 }}
|
||||
|
||||
pub fn C_u8(ccx: &CrateContext, i: u8) -> ValueRef {
|
||||
C_integral(Type::i8(ccx), i as u64, false)
|
||||
C_uint(Type::i8(ccx), i as u64)
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -315,7 +306,7 @@ pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> Va
|
|||
pub fn C_str_slice(cx: &CrateContext, s: InternedString) -> ValueRef {
|
||||
let len = s.len();
|
||||
let cs = consts::ptrcast(C_cstr(cx, s, false), Type::i8p(cx));
|
||||
C_named_struct(cx.str_slice_type(), &[cs, C_uint(cx, len)])
|
||||
C_named_struct(cx.str_slice_type(), &[cs, C_usize(cx, len as u64)])
|
||||
}
|
||||
|
||||
pub fn C_struct(cx: &CrateContext, elts: &[ValueRef], packed: bool) -> ValueRef {
|
||||
|
|
@ -482,9 +473,9 @@ pub fn shift_mask_val<'a, 'tcx>(
|
|||
// i8/u8 can shift by at most 7, i16/u16 by at most 15, etc.
|
||||
let val = llty.int_width() - 1;
|
||||
if invert {
|
||||
C_integral(mask_llty, !val, true)
|
||||
C_int(mask_llty, !val as i64)
|
||||
} else {
|
||||
C_integral(mask_llty, val, false)
|
||||
C_uint(mask_llty, val)
|
||||
}
|
||||
},
|
||||
TypeKind::Vector => {
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ pub struct LocalCrateContext<'a, 'tcx: 'a> {
|
|||
used_statics: RefCell<Vec<ValueRef>>,
|
||||
|
||||
lltypes: RefCell<FxHashMap<Ty<'tcx>, Type>>,
|
||||
int_type: Type,
|
||||
isize_ty: Type,
|
||||
opaque_vec_type: Type,
|
||||
str_slice_type: Type,
|
||||
|
||||
|
|
@ -398,7 +398,7 @@ impl<'a, 'tcx> LocalCrateContext<'a, 'tcx> {
|
|||
statics_to_rauw: RefCell::new(Vec::new()),
|
||||
used_statics: RefCell::new(Vec::new()),
|
||||
lltypes: RefCell::new(FxHashMap()),
|
||||
int_type: Type::from_ref(ptr::null_mut()),
|
||||
isize_ty: Type::from_ref(ptr::null_mut()),
|
||||
opaque_vec_type: Type::from_ref(ptr::null_mut()),
|
||||
str_slice_type: Type::from_ref(ptr::null_mut()),
|
||||
dbg_cx,
|
||||
|
|
@ -410,23 +410,23 @@ impl<'a, 'tcx> LocalCrateContext<'a, 'tcx> {
|
|||
placeholder: PhantomData,
|
||||
};
|
||||
|
||||
let (int_type, opaque_vec_type, str_slice_ty, mut local_ccx) = {
|
||||
let (isize_ty, opaque_vec_type, str_slice_ty, mut local_ccx) = {
|
||||
// Do a little dance to create a dummy CrateContext, so we can
|
||||
// create some things in the LLVM module of this codegen unit
|
||||
let mut local_ccxs = vec![local_ccx];
|
||||
let (int_type, opaque_vec_type, str_slice_ty) = {
|
||||
let (isize_ty, opaque_vec_type, str_slice_ty) = {
|
||||
let dummy_ccx = LocalCrateContext::dummy_ccx(shared,
|
||||
local_ccxs.as_mut_slice());
|
||||
let mut str_slice_ty = Type::named_struct(&dummy_ccx, "str_slice");
|
||||
str_slice_ty.set_struct_body(&[Type::i8p(&dummy_ccx),
|
||||
Type::int(&dummy_ccx)],
|
||||
Type::isize(&dummy_ccx)],
|
||||
false);
|
||||
(Type::int(&dummy_ccx), Type::opaque_vec(&dummy_ccx), str_slice_ty)
|
||||
(Type::isize(&dummy_ccx), Type::opaque_vec(&dummy_ccx), str_slice_ty)
|
||||
};
|
||||
(int_type, opaque_vec_type, str_slice_ty, local_ccxs.pop().unwrap())
|
||||
(isize_ty, opaque_vec_type, str_slice_ty, local_ccxs.pop().unwrap())
|
||||
};
|
||||
|
||||
local_ccx.int_type = int_type;
|
||||
local_ccx.isize_ty = isize_ty;
|
||||
local_ccx.opaque_vec_type = opaque_vec_type;
|
||||
local_ccx.str_slice_type = str_slice_ty;
|
||||
|
||||
|
|
@ -549,8 +549,8 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
|
|||
&self.local().stats
|
||||
}
|
||||
|
||||
pub fn int_type(&self) -> Type {
|
||||
self.local().int_type
|
||||
pub fn isize_ty(&self) -> Type {
|
||||
self.local().isize_ty
|
||||
}
|
||||
|
||||
pub fn str_slice_type(&self) -> Type {
|
||||
|
|
|
|||
|
|
@ -366,7 +366,7 @@ fn vec_slice_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
|||
-> bool {
|
||||
member_llvm_types.len() == 2 &&
|
||||
member_llvm_types[0] == type_of::type_of(cx, element_type).ptr_to() &&
|
||||
member_llvm_types[1] == cx.int_type()
|
||||
member_llvm_types[1] == cx.isize_ty()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -530,7 +530,7 @@ pub fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
|||
MetadataCreationResult::new(basic_type_metadata(cx, t), false)
|
||||
}
|
||||
ty::TyArray(typ, len) => {
|
||||
fixed_vec_metadata(cx, unique_type_id, typ, Some(len as u64), usage_site_span)
|
||||
fixed_vec_metadata(cx, unique_type_id, typ, Some(len.as_u64()), usage_site_span)
|
||||
}
|
||||
ty::TySlice(typ) => {
|
||||
fixed_vec_metadata(cx, unique_type_id, typ, None, usage_site_span)
|
||||
|
|
|
|||
|
|
@ -70,8 +70,8 @@ pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, inf
|
|||
let align = bcx.ccx.align_of(t);
|
||||
debug!("size_and_align_of_dst t={} info={:?} size: {} align: {}",
|
||||
t, Value(info), size, align);
|
||||
let size = C_uint(bcx.ccx, size);
|
||||
let align = C_uint(bcx.ccx, align);
|
||||
let size = C_usize(bcx.ccx, size);
|
||||
let align = C_usize(bcx.ccx, align as u64);
|
||||
return (size, align);
|
||||
}
|
||||
assert!(!info.is_null());
|
||||
|
|
@ -96,8 +96,8 @@ pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, inf
|
|||
};
|
||||
debug!("DST {} statically sized prefix size: {} align: {}",
|
||||
t, sized_size, sized_align);
|
||||
let sized_size = C_uint(ccx, sized_size);
|
||||
let sized_align = C_uint(ccx, sized_align);
|
||||
let sized_size = C_usize(ccx, sized_size);
|
||||
let sized_align = C_usize(ccx, sized_align);
|
||||
|
||||
// Recurse to get the size of the dynamically sized field (must be
|
||||
// the last field).
|
||||
|
|
@ -128,7 +128,7 @@ pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, inf
|
|||
(Some(sized_align), Some(unsized_align)) => {
|
||||
// If both alignments are constant, (the sized_align should always be), then
|
||||
// pick the correct alignment statically.
|
||||
C_uint(ccx, std::cmp::max(sized_align, unsized_align) as u64)
|
||||
C_usize(ccx, std::cmp::max(sized_align, unsized_align) as u64)
|
||||
}
|
||||
_ => bcx.select(bcx.icmp(llvm::IntUGT, sized_align, unsized_align),
|
||||
sized_align,
|
||||
|
|
@ -146,7 +146,7 @@ pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, inf
|
|||
//
|
||||
// `(size + (align-1)) & -align`
|
||||
|
||||
let addend = bcx.sub(align, C_uint(bcx.ccx, 1_u64));
|
||||
let addend = bcx.sub(align, C_usize(bcx.ccx, 1));
|
||||
let size = bcx.and(bcx.add(size, addend), bcx.neg(align));
|
||||
|
||||
(size, align)
|
||||
|
|
@ -159,8 +159,8 @@ pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, inf
|
|||
let unit = t.sequence_element_type(bcx.tcx());
|
||||
// The info in this case is the length of the str, so the size is that
|
||||
// times the unit size.
|
||||
(bcx.mul(info, C_uint(bcx.ccx, bcx.ccx.size_of(unit))),
|
||||
C_uint(bcx.ccx, bcx.ccx.align_of(unit)))
|
||||
(bcx.mul(info, C_usize(bcx.ccx, bcx.ccx.size_of(unit))),
|
||||
C_usize(bcx.ccx, bcx.ccx.align_of(unit) as u64))
|
||||
}
|
||||
_ => bug!("Unexpected unsized type, found {}", t)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
|
|||
"size_of" => {
|
||||
let tp_ty = substs.type_at(0);
|
||||
let lltp_ty = type_of::type_of(ccx, tp_ty);
|
||||
C_uint(ccx, machine::llsize_of_alloc(ccx, lltp_ty))
|
||||
C_usize(ccx, machine::llsize_of_alloc(ccx, lltp_ty))
|
||||
}
|
||||
"size_of_val" => {
|
||||
let tp_ty = substs.type_at(0);
|
||||
|
|
@ -145,12 +145,12 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
|
|||
llsize
|
||||
} else {
|
||||
let lltp_ty = type_of::type_of(ccx, tp_ty);
|
||||
C_uint(ccx, machine::llsize_of_alloc(ccx, lltp_ty))
|
||||
C_usize(ccx, machine::llsize_of_alloc(ccx, lltp_ty))
|
||||
}
|
||||
}
|
||||
"min_align_of" => {
|
||||
let tp_ty = substs.type_at(0);
|
||||
C_uint(ccx, ccx.align_of(tp_ty))
|
||||
C_usize(ccx, ccx.align_of(tp_ty) as u64)
|
||||
}
|
||||
"min_align_of_val" => {
|
||||
let tp_ty = substs.type_at(0);
|
||||
|
|
@ -159,13 +159,13 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
|
|||
glue::size_and_align_of_dst(bcx, tp_ty, llargs[1]);
|
||||
llalign
|
||||
} else {
|
||||
C_uint(ccx, ccx.align_of(tp_ty))
|
||||
C_usize(ccx, ccx.align_of(tp_ty) as u64)
|
||||
}
|
||||
}
|
||||
"pref_align_of" => {
|
||||
let tp_ty = substs.type_at(0);
|
||||
let lltp_ty = type_of::type_of(ccx, tp_ty);
|
||||
C_uint(ccx, machine::llalign_of_pref(ccx, lltp_ty))
|
||||
C_usize(ccx, machine::llalign_of_pref(ccx, lltp_ty) as u64)
|
||||
}
|
||||
"type_name" => {
|
||||
let tp_ty = substs.type_at(0);
|
||||
|
|
@ -182,7 +182,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
|
|||
// If we store a zero constant, LLVM will drown in vreg allocation for large data
|
||||
// structures, and the generated code will be awful. (A telltale sign of this is
|
||||
// large quantities of `mov [byte ptr foo],0` in the generated code.)
|
||||
memset_intrinsic(bcx, false, ty, llresult, C_u8(ccx, 0), C_uint(ccx, 1usize));
|
||||
memset_intrinsic(bcx, false, ty, llresult, C_u8(ccx, 0), C_usize(ccx, 1));
|
||||
}
|
||||
C_nil(ccx)
|
||||
}
|
||||
|
|
@ -386,10 +386,10 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
|
|||
|
||||
"align_offset" => {
|
||||
// `ptr as usize`
|
||||
let ptr_val = bcx.ptrtoint(llargs[0], bcx.ccx.int_type());
|
||||
let ptr_val = bcx.ptrtoint(llargs[0], bcx.ccx.isize_ty());
|
||||
// `ptr_val % align`
|
||||
let offset = bcx.urem(ptr_val, llargs[1]);
|
||||
let zero = C_null(bcx.ccx.int_type());
|
||||
let zero = C_null(bcx.ccx.isize_ty());
|
||||
// `offset == 0`
|
||||
let is_zero = bcx.icmp(llvm::IntPredicate::IntEQ, offset, zero);
|
||||
// `if offset == 0 { 0 } else { offset - align }`
|
||||
|
|
@ -688,7 +688,7 @@ fn copy_intrinsic<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
|
|||
let lltp_ty = type_of::type_of(ccx, tp_ty);
|
||||
let align = C_i32(ccx, ccx.align_of(tp_ty) as i32);
|
||||
let size = machine::llsize_of(ccx, lltp_ty);
|
||||
let int_size = machine::llbitsize_of_real(ccx, ccx.int_type());
|
||||
let int_size = machine::llbitsize_of_real(ccx, ccx.isize_ty());
|
||||
|
||||
let operation = if allow_overlap {
|
||||
"memmove"
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ pub fn llsize_of(cx: &CrateContext, ty: Type) -> ValueRef {
|
|||
// there's no need for that contrivance. The instruction
|
||||
// selection DAG generator would flatten that GEP(1) node into a
|
||||
// constant of the type's alloc size, so let's save it some work.
|
||||
return C_uint(cx, llsize_of_alloc(cx, ty));
|
||||
return C_usize(cx, llsize_of_alloc(cx, ty));
|
||||
}
|
||||
|
||||
// Returns the preferred alignment of the given type for the current target.
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ impl<'a, 'tcx> VirtualIndex {
|
|||
// Load the data pointer from the object.
|
||||
debug!("get_int({:?}, {:?})", Value(llvtable), self);
|
||||
|
||||
let llvtable = bcx.pointercast(llvtable, Type::int(bcx.ccx).ptr_to());
|
||||
let llvtable = bcx.pointercast(llvtable, Type::isize(bcx.ccx).ptr_to());
|
||||
let ptr = bcx.load(bcx.gepi(llvtable, &[self.0]), None);
|
||||
// Vtable loads are invariant
|
||||
bcx.set_invariant_load(ptr);
|
||||
|
|
@ -81,8 +81,8 @@ pub fn get_vtable<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||
|
||||
let mut components: Vec<_> = [
|
||||
callee::get_fn(ccx, monomorphize::resolve_drop_in_place(ccx.shared(), ty)),
|
||||
C_uint(ccx, ccx.size_of(ty)),
|
||||
C_uint(ccx, ccx.align_of(ty))
|
||||
C_usize(ccx, ccx.size_of(ty)),
|
||||
C_usize(ccx, ccx.align_of(ty) as u64)
|
||||
].iter().cloned().collect();
|
||||
|
||||
if let Some(trait_ref) = trait_ref {
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ use abi::{self, Abi};
|
|||
use callee;
|
||||
use builder::Builder;
|
||||
use common::{self, CrateContext, const_get_elt, val_ty};
|
||||
use common::{C_array, C_bool, C_bytes, C_integral, C_big_integral, C_u32, C_u64};
|
||||
use common::{C_null, C_struct, C_str_slice, C_undef, C_uint, C_vector, is_undef};
|
||||
use common::{C_array, C_bool, C_bytes, C_int, C_uint, C_big_integral, C_u32, C_u64};
|
||||
use common::{C_null, C_struct, C_str_slice, C_undef, C_usize, C_vector, is_undef};
|
||||
use common::const_to_opt_u128;
|
||||
use consts;
|
||||
use monomorphize;
|
||||
|
|
@ -66,24 +66,18 @@ impl<'tcx> Const<'tcx> {
|
|||
-> Const<'tcx> {
|
||||
let tcx = ccx.tcx();
|
||||
let (llval, ty) = match *ci {
|
||||
I8(v) => (C_integral(Type::i8(ccx), v as u64, true), tcx.types.i8),
|
||||
I16(v) => (C_integral(Type::i16(ccx), v as u64, true), tcx.types.i16),
|
||||
I32(v) => (C_integral(Type::i32(ccx), v as u64, true), tcx.types.i32),
|
||||
I64(v) => (C_integral(Type::i64(ccx), v as u64, true), tcx.types.i64),
|
||||
I8(v) => (C_int(Type::i8(ccx), v as i64), tcx.types.i8),
|
||||
I16(v) => (C_int(Type::i16(ccx), v as i64), tcx.types.i16),
|
||||
I32(v) => (C_int(Type::i32(ccx), v as i64), tcx.types.i32),
|
||||
I64(v) => (C_int(Type::i64(ccx), v as i64), tcx.types.i64),
|
||||
I128(v) => (C_big_integral(Type::i128(ccx), v as u128), tcx.types.i128),
|
||||
Isize(v) => {
|
||||
let i = v.as_i64(ccx.tcx().sess.target.int_type);
|
||||
(C_integral(Type::int(ccx), i as u64, true), tcx.types.isize)
|
||||
},
|
||||
U8(v) => (C_integral(Type::i8(ccx), v as u64, false), tcx.types.u8),
|
||||
U16(v) => (C_integral(Type::i16(ccx), v as u64, false), tcx.types.u16),
|
||||
U32(v) => (C_integral(Type::i32(ccx), v as u64, false), tcx.types.u32),
|
||||
U64(v) => (C_integral(Type::i64(ccx), v, false), tcx.types.u64),
|
||||
Isize(v) => (C_int(Type::isize(ccx), v.as_i64()), tcx.types.isize),
|
||||
U8(v) => (C_uint(Type::i8(ccx), v as u64), tcx.types.u8),
|
||||
U16(v) => (C_uint(Type::i16(ccx), v as u64), tcx.types.u16),
|
||||
U32(v) => (C_uint(Type::i32(ccx), v as u64), tcx.types.u32),
|
||||
U64(v) => (C_uint(Type::i64(ccx), v), tcx.types.u64),
|
||||
U128(v) => (C_big_integral(Type::i128(ccx), v), tcx.types.u128),
|
||||
Usize(v) => {
|
||||
let u = v.as_u64(ccx.tcx().sess.target.uint_type);
|
||||
(C_integral(Type::int(ccx), u, false), tcx.types.usize)
|
||||
},
|
||||
Usize(v) => (C_uint(Type::isize(ccx), v.as_u64()), tcx.types.usize),
|
||||
};
|
||||
Const { llval: llval, ty: ty }
|
||||
}
|
||||
|
|
@ -106,7 +100,7 @@ impl<'tcx> Const<'tcx> {
|
|||
ConstVal::Integral(ref i) => return Const::from_constint(ccx, i),
|
||||
ConstVal::Str(ref v) => C_str_slice(ccx, v.clone()),
|
||||
ConstVal::ByteStr(v) => consts::addr_of(ccx, C_bytes(ccx, v.data), 1, "byte_str"),
|
||||
ConstVal::Char(c) => C_integral(Type::char(ccx), c as u64, false),
|
||||
ConstVal::Char(c) => C_uint(Type::char(ccx), c as u64),
|
||||
ConstVal::Function(..) => C_null(type_of::type_of(ccx, ty)),
|
||||
ConstVal::Variant(_) |
|
||||
ConstVal::Aggregate(..) => {
|
||||
|
|
@ -206,7 +200,7 @@ impl<'tcx> ConstLvalue<'tcx> {
|
|||
|
||||
pub fn len<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> ValueRef {
|
||||
match self.ty.sty {
|
||||
ty::TyArray(_, n) => C_uint(ccx, n),
|
||||
ty::TyArray(_, n) => C_usize(ccx, n.as_u64()),
|
||||
ty::TySlice(_) | ty::TyStr => {
|
||||
assert!(self.llextra != ptr::null_mut());
|
||||
self.llextra
|
||||
|
|
@ -366,13 +360,13 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
|
|||
let result = if fn_ty.fn_sig(tcx).abi() == Abi::RustIntrinsic {
|
||||
match &tcx.item_name(def_id)[..] {
|
||||
"size_of" => {
|
||||
let llval = C_uint(self.ccx,
|
||||
let llval = C_usize(self.ccx,
|
||||
self.ccx.size_of(substs.type_at(0)));
|
||||
Ok(Const::new(llval, tcx.types.usize))
|
||||
}
|
||||
"min_align_of" => {
|
||||
let llval = C_uint(self.ccx,
|
||||
self.ccx.align_of(substs.type_at(0)));
|
||||
let llval = C_usize(self.ccx,
|
||||
self.ccx.align_of(substs.type_at(0)) as u64);
|
||||
Ok(Const::new(llval, tcx.types.usize))
|
||||
}
|
||||
_ => span_bug!(span, "{:?} in constant", terminator.kind)
|
||||
|
|
@ -556,9 +550,10 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
|
|||
let val = match *rvalue {
|
||||
mir::Rvalue::Use(ref operand) => self.const_operand(operand, span)?,
|
||||
|
||||
mir::Rvalue::Repeat(ref elem, ref count) => {
|
||||
mir::Rvalue::Repeat(ref elem, count) => {
|
||||
let elem = self.const_operand(elem, span)?;
|
||||
let size = count.as_u64(tcx.sess.target.uint_type);
|
||||
let size = count.as_u64();
|
||||
assert_eq!(size as usize as u64, size);
|
||||
let fields = vec![elem.llval; size as usize];
|
||||
self.const_array(dest_ty, &fields)
|
||||
}
|
||||
|
|
@ -835,7 +830,7 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
|
|||
|
||||
mir::Rvalue::NullaryOp(mir::NullOp::SizeOf, ty) => {
|
||||
assert!(self.ccx.shared().type_is_sized(ty));
|
||||
let llval = C_uint(self.ccx, self.ccx.size_of(ty));
|
||||
let llval = C_usize(self.ccx, self.ccx.size_of(ty));
|
||||
Const::new(llval, tcx.types.usize)
|
||||
}
|
||||
|
||||
|
|
@ -853,10 +848,10 @@ fn to_const_int(value: ValueRef, t: Ty, tcx: TyCtxt) -> Option<ConstInt> {
|
|||
match t.sty {
|
||||
ty::TyInt(int_type) => const_to_opt_u128(value, true)
|
||||
.and_then(|input| ConstInt::new_signed(input as i128, int_type,
|
||||
tcx.sess.target.int_type)),
|
||||
tcx.sess.target.isize_ty)),
|
||||
ty::TyUint(uint_type) => const_to_opt_u128(value, false)
|
||||
.and_then(|input| ConstInt::new_unsigned(input, uint_type,
|
||||
tcx.sess.target.uint_type)),
|
||||
tcx.sess.target.usize_ty)),
|
||||
_ => None
|
||||
|
||||
}
|
||||
|
|
@ -1037,11 +1032,11 @@ fn trans_const<'a, 'tcx>(
|
|||
};
|
||||
assert_eq!(vals.len(), 0);
|
||||
adt::assert_discr_in_range(min, max, discr);
|
||||
C_integral(Type::from_integer(ccx, d), discr, true)
|
||||
C_int(Type::from_integer(ccx, d), discr as i64)
|
||||
}
|
||||
layout::General { discr: d, ref variants, .. } => {
|
||||
let variant = &variants[variant_index];
|
||||
let lldiscr = C_integral(Type::from_integer(ccx, d), variant_index as u64, true);
|
||||
let lldiscr = C_int(Type::from_integer(ccx, d), variant_index as i64);
|
||||
let mut vals_with_discr = vec![lldiscr];
|
||||
vals_with_discr.extend_from_slice(vals);
|
||||
let mut contents = build_const_struct(ccx, &variant, &vals_with_discr[..]);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use rustc::mir::tcx::LvalueTy;
|
|||
use rustc_data_structures::indexed_vec::Idx;
|
||||
use adt;
|
||||
use builder::Builder;
|
||||
use common::{self, CrateContext, C_uint};
|
||||
use common::{self, CrateContext, C_usize};
|
||||
use consts;
|
||||
use machine;
|
||||
use type_of;
|
||||
|
|
@ -106,7 +106,7 @@ impl<'a, 'tcx> LvalueRef<'tcx> {
|
|||
pub fn len(&self, ccx: &CrateContext<'a, 'tcx>) -> ValueRef {
|
||||
let ty = self.ty.to_ty(ccx.tcx());
|
||||
match ty.sty {
|
||||
ty::TyArray(_, n) => common::C_uint(ccx, n),
|
||||
ty::TyArray(_, n) => common::C_usize(ccx, n.as_u64()),
|
||||
ty::TySlice(_) | ty::TyStr => {
|
||||
assert!(self.llextra != ptr::null_mut());
|
||||
self.llextra
|
||||
|
|
@ -186,7 +186,7 @@ impl<'a, 'tcx> LvalueRef<'tcx> {
|
|||
|
||||
|
||||
let offset = st.offsets[ix].bytes();
|
||||
let unaligned_offset = C_uint(bcx.ccx, offset);
|
||||
let unaligned_offset = C_usize(bcx.ccx, offset);
|
||||
|
||||
// Get the alignment of the field
|
||||
let (_, align) = glue::size_and_align_of_dst(bcx, fty, meta);
|
||||
|
|
@ -197,7 +197,7 @@ impl<'a, 'tcx> LvalueRef<'tcx> {
|
|||
// (unaligned offset + (align - 1)) & -align
|
||||
|
||||
// Calculate offset
|
||||
let align_sub_1 = bcx.sub(align, C_uint(bcx.ccx, 1u64));
|
||||
let align_sub_1 = bcx.sub(align, C_usize(bcx.ccx, 1));
|
||||
let offset = bcx.and(bcx.add(unaligned_offset, align_sub_1),
|
||||
bcx.neg(align));
|
||||
|
||||
|
|
@ -276,7 +276,7 @@ impl<'a, 'tcx> LvalueRef<'tcx> {
|
|||
// Slices already point to the array element type.
|
||||
bcx.inbounds_gep(self.llval, &[llindex])
|
||||
} else {
|
||||
let zero = common::C_uint(bcx.ccx, 0u64);
|
||||
let zero = common::C_usize(bcx.ccx, 0);
|
||||
bcx.inbounds_gep(self.llval, &[zero, llindex])
|
||||
}
|
||||
}
|
||||
|
|
@ -342,19 +342,19 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
|||
mir::ProjectionElem::ConstantIndex { offset,
|
||||
from_end: false,
|
||||
min_length: _ } => {
|
||||
let lloffset = C_uint(bcx.ccx, offset);
|
||||
let lloffset = C_usize(bcx.ccx, offset as u64);
|
||||
((tr_base.project_index(bcx, lloffset), align), ptr::null_mut())
|
||||
}
|
||||
mir::ProjectionElem::ConstantIndex { offset,
|
||||
from_end: true,
|
||||
min_length: _ } => {
|
||||
let lloffset = C_uint(bcx.ccx, offset);
|
||||
let lloffset = C_usize(bcx.ccx, offset as u64);
|
||||
let lllen = tr_base.len(bcx.ccx);
|
||||
let llindex = bcx.sub(lllen, lloffset);
|
||||
((tr_base.project_index(bcx, llindex), align), ptr::null_mut())
|
||||
}
|
||||
mir::ProjectionElem::Subslice { from, to } => {
|
||||
let llbase = tr_base.project_index(bcx, C_uint(bcx.ccx, from));
|
||||
let llbase = tr_base.project_index(bcx, C_usize(bcx.ccx, from as u64));
|
||||
|
||||
let base_ty = tr_base.ty.to_ty(bcx.tcx());
|
||||
match base_ty.sty {
|
||||
|
|
@ -369,7 +369,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
|||
ty::TySlice(..) => {
|
||||
assert!(tr_base.llextra != ptr::null_mut());
|
||||
let lllen = bcx.sub(tr_base.llextra,
|
||||
C_uint(bcx.ccx, from+to));
|
||||
C_usize(bcx.ccx, (from as u64)+(to as u64)));
|
||||
((llbase, align), lllen)
|
||||
}
|
||||
_ => bug!("unexpected type {:?} in Subslice", base_ty)
|
||||
|
|
@ -397,11 +397,11 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
|||
/// nmatsakis: is this still necessary? Not sure.
|
||||
fn prepare_index(&mut self, bcx: &Builder<'a, 'tcx>, llindex: ValueRef) -> ValueRef {
|
||||
let index_size = machine::llbitsize_of_real(bcx.ccx, common::val_ty(llindex));
|
||||
let int_size = machine::llbitsize_of_real(bcx.ccx, bcx.ccx.int_type());
|
||||
let int_size = machine::llbitsize_of_real(bcx.ccx, bcx.ccx.isize_ty());
|
||||
if index_size < int_size {
|
||||
bcx.zext(llindex, bcx.ccx.int_type())
|
||||
bcx.zext(llindex, bcx.ccx.isize_ty())
|
||||
} else if index_size > int_size {
|
||||
bcx.trunc(llindex, bcx.ccx.int_type())
|
||||
bcx.trunc(llindex, bcx.ccx.isize_ty())
|
||||
} else {
|
||||
llindex
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,7 @@ use rustc::middle::lang_items::ExchangeMallocFnLangItem;
|
|||
use base;
|
||||
use builder::Builder;
|
||||
use callee;
|
||||
use common::{self, val_ty, C_bool, C_null, C_uint};
|
||||
use common::{C_integral, C_i32};
|
||||
use common::{self, val_ty, C_bool, C_i32, C_null, C_usize, C_uint};
|
||||
use adt;
|
||||
use machine;
|
||||
use monomorphize;
|
||||
|
|
@ -92,7 +91,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
|||
bcx
|
||||
}
|
||||
|
||||
mir::Rvalue::Repeat(ref elem, ref count) => {
|
||||
mir::Rvalue::Repeat(ref elem, count) => {
|
||||
let dest_ty = dest.ty.to_ty(bcx.tcx());
|
||||
|
||||
// No need to inizialize memory of a zero-sized slice
|
||||
|
|
@ -101,8 +100,8 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
let tr_elem = self.trans_operand(&bcx, elem);
|
||||
let size = count.as_u64(bcx.tcx().sess.target.uint_type);
|
||||
let size = C_uint(bcx.ccx, size);
|
||||
let size = count.as_u64();
|
||||
let size = C_usize(bcx.ccx, size);
|
||||
let base = base::get_dataptr(&bcx, dest.llval);
|
||||
let align = dest.alignment.to_align();
|
||||
|
||||
|
|
@ -113,7 +112,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
|||
let align = C_i32(bcx.ccx, align as i32);
|
||||
let ty = type_of::type_of(bcx.ccx, dest_ty);
|
||||
let size = machine::llsize_of(bcx.ccx, ty);
|
||||
let fill = C_integral(Type::i8(bcx.ccx), 0, false);
|
||||
let fill = C_uint(Type::i8(bcx.ccx), 0);
|
||||
base::call_memset(&bcx, base, fill, size, align, false);
|
||||
return bcx;
|
||||
}
|
||||
|
|
@ -301,7 +300,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
|||
base::call_assume(&bcx, bcx.icmp(
|
||||
llvm::IntULE,
|
||||
llval,
|
||||
C_integral(common::val_ty(llval), max, false)
|
||||
C_uint(common::val_ty(llval), max)
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -464,7 +463,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
|||
|
||||
mir::Rvalue::NullaryOp(mir::NullOp::SizeOf, ty) => {
|
||||
assert!(bcx.ccx.shared().type_is_sized(ty));
|
||||
let val = C_uint(bcx.ccx, bcx.ccx.size_of(ty));
|
||||
let val = C_usize(bcx.ccx, bcx.ccx.size_of(ty));
|
||||
let tcx = bcx.tcx();
|
||||
(bcx, OperandRef {
|
||||
val: OperandValue::Immediate(val),
|
||||
|
|
@ -477,7 +476,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
|||
let llty = type_of::type_of(bcx.ccx, content_ty);
|
||||
let llsize = machine::llsize_of(bcx.ccx, llty);
|
||||
let align = bcx.ccx.align_of(content_ty);
|
||||
let llalign = C_uint(bcx.ccx, align);
|
||||
let llalign = C_usize(bcx.ccx, align as u64);
|
||||
let llty_ptr = llty.ptr_to();
|
||||
let box_ty = bcx.tcx().mk_box(content_ty);
|
||||
|
||||
|
|
@ -522,7 +521,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
|||
if let LocalRef::Operand(Some(op)) = self.locals[index] {
|
||||
if common::type_is_zero_size(bcx.ccx, op.ty) {
|
||||
if let ty::TyArray(_, n) = op.ty.sty {
|
||||
return common::C_uint(bcx.ccx, n);
|
||||
return common::C_usize(bcx.ccx, n.as_u64());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ pub fn slice_for_each<'a, 'tcx, F>(
|
|||
let next_bcx = bcx.build_sibling_block("slice_loop_next");
|
||||
|
||||
let start = if zst {
|
||||
C_uint(bcx.ccx, 0usize)
|
||||
C_usize(bcx.ccx, 1)
|
||||
} else {
|
||||
data_ptr
|
||||
};
|
||||
|
|
@ -46,7 +46,7 @@ pub fn slice_for_each<'a, 'tcx, F>(
|
|||
let keep_going = header_bcx.icmp(llvm::IntNE, current, end);
|
||||
header_bcx.cond_br(keep_going, body_bcx.llbb(), next_bcx.llbb());
|
||||
|
||||
let next = add(&body_bcx, current, C_uint(bcx.ccx, 1usize));
|
||||
let next = add(&body_bcx, current, C_usize(bcx.ccx, 1));
|
||||
f(&body_bcx, if zst { data_ptr } else { current }, header_bcx.llbb());
|
||||
header_bcx.add_incoming_to_phi(current, next, body_bcx.llbb());
|
||||
next_bcx
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ impl Type {
|
|||
Type::i8_llcx(llcx).ptr_to()
|
||||
}
|
||||
|
||||
pub fn int(ccx: &CrateContext) -> Type {
|
||||
pub fn isize(ccx: &CrateContext) -> Type {
|
||||
match &ccx.tcx().sess.target.target.target_pointer_width[..] {
|
||||
"16" => Type::i16(ccx),
|
||||
"32" => Type::i32(ccx),
|
||||
|
|
@ -142,7 +142,7 @@ impl Type {
|
|||
|
||||
pub fn int_from_ty(ccx: &CrateContext, t: ast::IntTy) -> Type {
|
||||
match t {
|
||||
ast::IntTy::Is => ccx.int_type(),
|
||||
ast::IntTy::Is => ccx.isize_ty(),
|
||||
ast::IntTy::I8 => Type::i8(ccx),
|
||||
ast::IntTy::I16 => Type::i16(ccx),
|
||||
ast::IntTy::I32 => Type::i32(ccx),
|
||||
|
|
@ -153,7 +153,7 @@ impl Type {
|
|||
|
||||
pub fn uint_from_ty(ccx: &CrateContext, t: ast::UintTy) -> Type {
|
||||
match t {
|
||||
ast::UintTy::Us => ccx.int_type(),
|
||||
ast::UintTy::Us => ccx.isize_ty(),
|
||||
ast::UintTy::U8 => Type::i8(ccx),
|
||||
ast::UintTy::U16 => Type::i16(ccx),
|
||||
ast::UintTy::U32 => Type::i32(ccx),
|
||||
|
|
@ -207,7 +207,7 @@ impl Type {
|
|||
|
||||
pub fn vec(ccx: &CrateContext, ty: &Type) -> Type {
|
||||
Type::struct_(ccx,
|
||||
&[Type::array(ty, 0), Type::int(ccx)],
|
||||
&[Type::array(ty, 0), Type::isize(ccx)],
|
||||
false)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -148,9 +148,8 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
|
|||
}
|
||||
|
||||
ty::TyArray(ty, size) => {
|
||||
let size = size as u64;
|
||||
let llty = in_memory_type_of(cx, ty);
|
||||
Type::array(&llty, size)
|
||||
Type::array(&llty, size.as_u64())
|
||||
}
|
||||
|
||||
// Unsized slice types (and str) have the type of their element, and
|
||||
|
|
|
|||
|
|
@ -1083,7 +1083,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||
}
|
||||
hir::TyArray(ref ty, length) => {
|
||||
if let Ok(length) = eval_length(tcx, length, "array length") {
|
||||
tcx.mk_array(self.ast_ty_to_ty(&ty), length)
|
||||
tcx.mk_array(self.ast_ty_to_ty(&ty), length.as_u64())
|
||||
} else {
|
||||
self.tcx().types.err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -264,7 +264,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
let expected_ty = self.structurally_resolved_type(pat.span, expected);
|
||||
let (inner_ty, slice_ty) = match expected_ty.sty {
|
||||
ty::TyArray(inner_ty, size) => {
|
||||
let min_len = before.len() + after.len();
|
||||
let size = size.as_u64();
|
||||
let min_len = before.len() as u64 + after.len() as u64;
|
||||
if slice.is_none() {
|
||||
if min_len != size {
|
||||
struct_span_err!(
|
||||
|
|
|
|||
|
|
@ -360,7 +360,7 @@ pub fn check_platform_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
match name["simd_shuffle".len()..].parse() {
|
||||
Ok(n) => {
|
||||
let params = vec![param(0), param(0),
|
||||
tcx.mk_ty(ty::TyArray(tcx.types.u32, n))];
|
||||
tcx.mk_array(tcx.types.u32, n)];
|
||||
(2, params, param(1))
|
||||
}
|
||||
Err(_) => {
|
||||
|
|
|
|||
|
|
@ -2636,7 +2636,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
ast::LitKind::Str(..) => tcx.mk_static_str(),
|
||||
ast::LitKind::ByteStr(ref v) => {
|
||||
tcx.mk_imm_ref(tcx.types.re_static,
|
||||
tcx.mk_array(tcx.types.u8, v.len()))
|
||||
tcx.mk_array(tcx.types.u8, v.len() as u64))
|
||||
}
|
||||
ast::LitKind::Byte(_) => tcx.types.u8,
|
||||
ast::LitKind::Char(_) => tcx.types.char,
|
||||
|
|
@ -3895,11 +3895,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
} else {
|
||||
self.next_ty_var(TypeVariableOrigin::TypeInference(expr.span))
|
||||
};
|
||||
tcx.mk_array(element_ty, args.len())
|
||||
tcx.mk_array(element_ty, args.len() as u64)
|
||||
}
|
||||
hir::ExprRepeat(ref element, count) => {
|
||||
let count = eval_length(self.tcx, count, "repeat count")
|
||||
.unwrap_or(0);
|
||||
let count = eval_length(self.tcx, count, "repeat count");
|
||||
|
||||
let uty = match expected {
|
||||
ExpectHasType(uty) => {
|
||||
|
|
@ -3923,17 +3922,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
};
|
||||
|
||||
if count > 1 {
|
||||
// For [foo, ..n] where n > 1, `foo` must have
|
||||
// Copy type:
|
||||
let lang_item = self.tcx.require_lang_item(lang_items::CopyTraitLangItem);
|
||||
self.require_type_meets(t, expr.span, traits::RepeatVec, lang_item);
|
||||
if let Ok(count) = count {
|
||||
if count.as_u64() > 1 {
|
||||
// For [foo, ..n] where n > 1, `foo` must have
|
||||
// Copy type:
|
||||
let lang_item = self.tcx.require_lang_item(lang_items::CopyTraitLangItem);
|
||||
self.require_type_meets(t, expr.span, traits::RepeatVec, lang_item);
|
||||
}
|
||||
}
|
||||
|
||||
if element_ty.references_error() {
|
||||
tcx.types.err
|
||||
} else if let Ok(count) = count {
|
||||
tcx.mk_ty(ty::TyArray(t, count))
|
||||
} else {
|
||||
tcx.mk_array(t, count)
|
||||
tcx.types.err
|
||||
}
|
||||
}
|
||||
hir::ExprTup(ref elts) => {
|
||||
|
|
|
|||
|
|
@ -1555,7 +1555,7 @@ pub enum Type {
|
|||
BareFunction(Box<BareFunctionDecl>),
|
||||
Tuple(Vec<Type>),
|
||||
Slice(Box<Type>),
|
||||
Array(Box<Type>, usize),
|
||||
Array(Box<Type>, String),
|
||||
Never,
|
||||
Unique(Box<Type>),
|
||||
RawPointer(Mutability, Box<Type>),
|
||||
|
|
@ -1785,7 +1785,7 @@ impl Clean<Type> for hir::Ty {
|
|||
TyArray(ref ty, length) => {
|
||||
use rustc::middle::const_val::eval_length;
|
||||
let n = eval_length(cx.tcx, length, "array length").unwrap();
|
||||
Array(box ty.clean(cx), n)
|
||||
Array(box ty.clean(cx), n.to_string())
|
||||
},
|
||||
TyTup(ref tys) => Tuple(tys.clean(cx)),
|
||||
TyPath(hir::QPath::Resolved(None, ref path)) => {
|
||||
|
|
@ -1895,7 +1895,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
|
|||
ty::TyFloat(float_ty) => Primitive(float_ty.into()),
|
||||
ty::TyStr => Primitive(PrimitiveType::Str),
|
||||
ty::TySlice(ty) => Slice(box ty.clean(cx)),
|
||||
ty::TyArray(ty, n) => Array(box ty.clean(cx), n),
|
||||
ty::TyArray(ty, n) => Array(box ty.clean(cx), n.to_string()),
|
||||
ty::TyRawPtr(mt) => RawPointer(mt.mutbl.clean(cx), box mt.ty.clean(cx)),
|
||||
ty::TyRef(r, mt) => BorrowedRef {
|
||||
lifetime: r.clean(cx),
|
||||
|
|
|
|||
|
|
@ -633,7 +633,7 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt:
|
|||
fmt::Display::fmt(t, f)?;
|
||||
primitive_link(f, PrimitiveType::Slice, "]")
|
||||
}
|
||||
clean::Array(ref t, n) => {
|
||||
clean::Array(ref t, ref n) => {
|
||||
primitive_link(f, PrimitiveType::Array, "[")?;
|
||||
fmt::Display::fmt(t, f)?;
|
||||
primitive_link(f, PrimitiveType::Array, &format!("; {}]", n))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue