ty::TyArray(t, sz) => {
mywrite!(w, "V");
enc_ty(w, cx, t);
- mywrite!(w, "/");
- match sz {
- Some(n) => mywrite!(w, "{}|", n),
- None => mywrite!(w, "|"),
- }
+ mywrite!(w, "/{}|", sz);
+ }
+ ty::TySlice(t) => {
+ mywrite!(w, "V");
+ enc_ty(w, cx, t);
+ mywrite!(w, "/|");
}
ty::TyStr => {
mywrite!(w, "v");
self.visit_expr(&**element);
// The count is checked elsewhere (typeck).
let count = match node_ty.sty {
- ty::TyArray(_, Some(n)) => n,
+ ty::TyArray(_, n) => n,
_ => unreachable!()
};
// [element; 0] is always zero-sized.
}
let mutbl = bk.to_mutbl_lossy();
if mutbl == ast::MutMutable && self.mode == Mode::StaticMut {
- // Mutable slices are the only `&mut` allowed in globals,
- // but only in `static mut`, nowhere else.
+ // Mutable slices are the only `&mut` allowed in
+ // globals, but only in `static mut`, nowhere else.
+ // FIXME: This exception is really weird... there isn't
+ // any fundamental reason to restrict this based on
+ // type of the expression. `&mut [1]` has exactly the
+ // same representation as &mut 1.
match cmt.ty.sty {
- ty::TyArray(_, _) => break,
+ ty::TyArray(_, _) | ty::TySlice(_) => break,
_ => {}
}
}
ty::TyRef(_, ty::mt { ty, mutbl }) => {
match ty.sty {
- ty::TyArray(_, Some(n)) => match ctor {
+ ty::TyArray(_, n) => match ctor {
&Single => {
assert_eq!(pats_len, n);
ast::PatVec(pats.collect(), None, vec!())
},
_ => unreachable!()
},
- ty::TyArray(_, None) => match ctor {
+ ty::TySlice(_) => match ctor {
&Slice(n) => {
assert_eq!(pats_len, n);
ast::PatVec(pats.collect(), None, vec!())
}
}
- ty::TyArray(_, Some(len)) => {
+ ty::TyArray(_, len) => {
assert_eq!(pats_len, len);
ast::PatVec(pats.collect(), None, vec![])
}
[true, false].iter().map(|b| ConstantValue(const_bool(*b))).collect(),
ty::TyRef(_, ty::mt { ty, .. }) => match ty.sty {
- ty::TyArray(_, None) =>
+ ty::TySlice(_) =>
range_inclusive(0, max_slice_length).map(|length| Slice(length)).collect(),
_ => vec!(Single)
},
vec!(ConstantRange(eval_const_expr(cx.tcx, &**lo), eval_const_expr(cx.tcx, &**hi))),
ast::PatVec(ref before, ref slice, ref after) =>
match left_ty.sty {
- ty::TyArray(_, Some(_)) => vec!(Single),
+ ty::TyArray(_, _) => vec!(Single),
_ => if slice.is_some() {
range_inclusive(before.len() + after.len(), max_slice_length)
.map(|length| Slice(length))
ty::TyTuple(ref fs) => fs.len(),
ty::TyBox(_) => 1,
ty::TyRef(_, ty::mt { ty, .. }) => match ty.sty {
- ty::TyArray(_, None) => match *ctor {
+ ty::TySlice(_) => match *ctor {
Slice(length) => length,
ConstantValue(_) => 0,
_ => unreachable!()
}
}
ty::TyStruct(cid, _) => ty::lookup_struct_fields(cx.tcx, cid).len(),
- ty::TyArray(_, Some(n)) => n,
+ ty::TyArray(_, n) => n,
_ => 0
}
}
ty::TyFloat(float_type) => Some(FloatSimplifiedType(float_type)),
ty::TyEnum(def_id, _) => Some(EnumSimplifiedType(def_id)),
ty::TyStr => Some(StrSimplifiedType),
- ty::TyArray(..) => Some(VecSimplifiedType),
+ ty::TyArray(..) | ty::TySlice(_) => Some(VecSimplifiedType),
ty::TyRawPtr(_) => Some(PtrSimplifiedType),
ty::TyTrait(ref trait_info) => {
Some(TraitSimplifiedType(trait_info.principal_def_id()))
}
ty::TyArray(t, _) |
+ ty::TySlice(t) |
ty::TyRawPtr(ty::mt { ty: t, .. }) |
ty::TyBox(t) => {
self.accumulate_from_ty(t)
ty::TyStr |
ty::TyError |
ty::TyArray(..) |
+ ty::TySlice(..) |
ty::TyRawPtr(..) |
ty::TyRef(..) |
ty::TyBareFn(..) |
Ok(deref_interior(InteriorField(PositionalField(0))))
}
- ty::TyArray(_, _) | ty::TyStr => {
+ ty::TyArray(_, _) | ty::TySlice(_) | ty::TyStr => {
// no deref of indexed content without supplying InteriorOffsetKind
if let Some(context) = context {
Ok(deref_interior(InteriorElement(context, element_kind(t))))
// Only promote `[T; 0]` before an RFC for rvalue promotions
// is accepted.
let qualif = match expr_ty.sty {
- ty::TyArray(_, Some(0)) => qualif,
+ ty::TyArray(_, 0) => qualif,
_ => check_const::ConstQualif::NOT_CONST
};
-> (ast::Mutability, ty::Region) {
match slice_ty.sty {
ty::TyRef(r, ref mt) => match mt.ty.sty {
- ty::TyArray(_, None) => (mt.mutbl, *r),
+ ty::TySlice(_) => (mt.mutbl, *r),
_ => vec_slice_info(tcx, pat, mt.ty),
},
match t.sty {
ty::TyRef(_, ty::mt{ty, ..}) |
ty::TyBox(ty) => match ty.sty {
- ty::TyArray(_, None) => VecElement,
+ ty::TySlice(_) => VecElement,
_ => OtherElement
},
- ty::TyArray(..) => VecElement,
+ ty::TyArray(..) | ty::TySlice(_) => VecElement,
_ => OtherElement
}
}
ty::TyStr(..) |
ty::TyBareFn(..) |
ty::TyArray(..) |
+ ty::TySlice(..) |
ty::TyRawPtr(..) |
ty::TyRef(..) |
ty::TyTuple(..) |
}
// [T; n] -> [T].
- (&ty::TyArray(_, Some(_)), &ty::TyArray(_, None)) => true,
+ (&ty::TyArray(_, _), &ty::TySlice(_)) => true,
// Struct<T> -> Struct<U>.
(&ty::TyStruct(def_id_a, _), &ty::TyStruct(def_id_b, _)) => {
}
}
- ty::TyArray(element_ty, ref len) => {
- // [T; n] and [T]
+ ty::TyArray(element_ty, _) => {
+ // [T; n]
match bound {
- ty::BoundCopy => {
- match *len {
- // [T; n] is copy iff T is copy
- Some(_) => ok_if(vec![element_ty]),
-
- // [T] is unsized and hence affine
- None => Err(Unimplemented),
- }
- }
-
- ty::BoundSized => {
- if len.is_some() {
- ok_if(Vec::new())
- } else {
- Err(Unimplemented)
- }
- }
-
+ ty::BoundCopy => ok_if(vec![element_ty]),
+ ty::BoundSized => ok_if(Vec::new()),
ty::BoundSync | ty::BoundSend => {
self.tcx().sess.bug("Send/Sync shouldn't occur in builtin_bounds()");
}
}
}
- ty::TyStr => {
- // Equivalent to [u8]
+ ty::TyStr | ty::TySlice(_) => {
match bound {
ty::BoundSync | ty::BoundSend => {
self.tcx().sess.bug("Send/Sync shouldn't occur in builtin_bounds()");
Some(vec![element_ty])
},
- ty::TyArray(element_ty, _) => {
+ ty::TyArray(element_ty, _) | ty::TySlice(element_ty) => {
Some(vec![element_ty])
}
}
// [T; n] -> [T].
- (&ty::TyArray(a, Some(_)), &ty::TyArray(b, None)) => {
+ (&ty::TyArray(a, _), &ty::TySlice(b)) => {
let origin = infer::Misc(obligation.cause.span);
if self.infcx.sub_types(false, origin, a, b).is_err() {
return Err(Unimplemented);
pub fn print_debug_stats(&self) {
sty_debug_print!(
self,
- TyEnum, TyBox, TyArray, TyRawPtr, TyRef, TyBareFn, TyTrait,
+ TyEnum, TyBox, TyArray, TySlice, TyRawPtr, TyRef, TyBareFn, TyTrait,
TyStruct, TyClosure, TyTuple, TyParam, TyInfer, TyProjection);
println!("Substs interner: #{}", self.substs_interner.borrow().len());
/// The pointee of a string slice. Written as `str`.
TyStr,
- /// An array with the given length, or the pointee
- /// of an array slice. Written as `[T; n]`, or `[T]`.
- /// FIXME: It probably makes sense to separate these.
- TyArray(Ty<'tcx>, Option<usize>),
+ /// An array with the given length. Written as `[T; n]`.
+ TyArray(Ty<'tcx>, usize),
+
+ /// The pointee of an array slice. Written as `[T]`.
+ TySlice(Ty<'tcx>),
/// A raw pointer. Written as `*mut T` or `*const T`
TyRawPtr(mt<'tcx>),
self.add_bounds(bounds);
}
- &TyBox(tt) | &TyArray(tt, _) => {
+ &TyBox(tt) | &TyArray(tt, _) | &TySlice(tt) => {
self.add_ty(tt)
}
}
pub fn mk_vec<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>, sz: Option<usize>) -> Ty<'tcx> {
- mk_t(cx, TyArray(ty, sz))
+ match sz {
+ Some(n) => mk_t(cx, TyArray(ty, n)),
+ None => mk_t(cx, TySlice(ty))
+ }
}
pub fn mk_slice<'tcx>(cx: &ctxt<'tcx>, r: &'tcx Region, tm: mt<'tcx>) -> Ty<'tcx> {
fn type_is_slice(ty: Ty) -> bool {
match ty.sty {
TyRawPtr(mt) | TyRef(_, mt) => match mt.ty.sty {
- TyArray(_, None) | TyStr => true,
+ TySlice(_) | TyStr => true,
_ => false,
},
_ => false
}
}
-pub fn type_is_vec(ty: Ty) -> bool {
- match ty.sty {
- TyArray(..) => true,
- TyRawPtr(mt{ty, ..}) | TyRef(_, mt{ty, ..}) |
- TyBox(ty) => match ty.sty {
- TyArray(_, None) => true,
- _ => false
- },
- _ => false
- }
-}
-
pub fn type_is_structural(ty: Ty) -> bool {
match ty.sty {
TyStruct(..) | TyTuple(_) | TyEnum(..) |
- TyArray(_, Some(_)) | TyClosure(..) => true,
+ TyArray(..) | TyClosure(..) => true,
_ => type_is_slice(ty) | type_is_trait(ty)
}
}
pub fn sequence_element_type<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
match ty.sty {
- TyArray(ty, _) => ty,
+ TyArray(ty, _) | TySlice(ty) => ty,
TyStr => mk_mach_uint(cx, ast::TyU8),
_ => cx.sess.bug(&format!("sequence_element_type called on non-sequence value: {}",
ty_to_string(cx, ty))),
TyRef(r, ref mt) => {
TC::ReachesFfiUnsafe | match mt.ty.sty {
TyStr => borrowed_contents(*r, ast::MutImmutable),
- TyArray(..) => tc_ty(cx, mt.ty, cache).reference(borrowed_contents(*r,
+ TyArray(..) |
+ TySlice(_) => tc_ty(cx, mt.ty, cache).reference(borrowed_contents(*r,
mt.mutbl)),
_ => tc_ty(cx, mt.ty, cache).reference(borrowed_contents(*r, mt.mutbl)),
}
}
- TyArray(ty, Some(_)) => {
+ TyArray(ty, _) => {
tc_ty(cx, ty, cache)
}
- TyArray(ty, None) => {
+ TySlice(ty) => {
tc_ty(cx, ty, cache) | TC::Nonsized
}
TyStr => TC::Nonsized,
mutbl: ast::MutMutable, ..
}) => Some(true),
- TyArray(..) | TyTrait(..) | TyTuple(..) |
+ TyArray(..) | TySlice(_) | TyTrait(..) | TyTuple(..) |
TyClosure(..) | TyEnum(..) | TyStruct(..) |
TyProjection(..) | TyParam(..) | TyInfer(..) | TyError => None
}.unwrap_or_else(|| !type_impls_bound(Some(param_env),
let result = match ty.sty {
TyBool | TyChar | TyInt(..) | TyUint(..) | TyFloat(..) |
TyBox(..) | TyRawPtr(..) | TyRef(..) | TyBareFn(..) |
- TyArray(_, Some(..)) | TyTuple(..) | TyClosure(..) => Some(true),
+ TyArray(..) | TyTuple(..) | TyClosure(..) => Some(true),
- TyStr | TyTrait(..) | TyArray(_, None) => Some(false),
+ TyStr | TyTrait(..) | TySlice(_) => Some(false),
TyEnum(..) | TyStruct(..) | TyProjection(..) | TyParam(..) |
TyInfer(..) | TyError => None
// fixed length vectors need special treatment compared to
// normal vectors, since they don't necessarily have the
// possibility to have length zero.
- TyArray(_, Some(0)) => false, // don't need no contents
- TyArray(ty, Some(_)) => type_requires(cx, seen, r_ty, ty),
+ TyArray(_, 0) => false, // don't need no contents
+ TyArray(ty, _) => type_requires(cx, seen, r_ty, ty),
TyBool |
TyChar |
TyBareFn(..) |
TyParam(_) |
TyProjection(_) |
- TyArray(_, None) => {
+ TySlice(_) => {
false
}
TyBox(typ) => {
}
// Fixed-length vectors.
// FIXME(#11924) Behavior undecided for zero-length vectors.
- TyArray(ty, Some(_)) => {
+ TyArray(ty, _) => {
is_type_structurally_recursive(cx, sp, seen, ty)
}
TyStruct(did, substs) => {
// Returns the type of ty[i]
pub fn index<'tcx>(ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
match ty.sty {
- TyArray(ty, _) => Some(ty),
+ TyArray(ty, _) | TySlice(ty) => Some(ty),
_ => None
}
}
// which can't actually be indexed.
pub fn array_element_ty<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
match ty.sty {
- TyArray(ty, _) => Some(ty),
+ TyArray(ty, _) | TySlice(ty) => Some(ty),
TyStr => Some(tcx.types.u8),
_ => None
}
TyEnum(id, _) => format!("enum `{}`", item_path_str(cx, id)),
TyBox(_) => "box".to_string(),
- TyArray(_, Some(n)) => format!("array of {} elements", n),
- TyArray(_, None) => "slice".to_string(),
+ TyArray(_, n) => format!("array of {} elements", n),
+ TySlice(_) => "slice".to_string(),
TyRawPtr(_) => "*-ptr".to_string(),
TyRef(_, _) => "&-ptr".to_string(),
TyBareFn(Some(_), _) => format!("fn item"),
TyBox(_) => {
byte!(9);
}
- TyArray(_, Some(n)) => {
+ TyArray(_, n) => {
byte!(10);
n.hash(state);
}
- TyArray(_, None) => {
+ TySlice(_) => {
byte!(11);
}
TyRawPtr(m) => {
TyBox(_) |
TyStr |
TyArray(_, _) |
+ TySlice(_) |
TyRawPtr(_) |
TyBareFn(..) |
TyTuple(_) |
ty::TyArray(typ, sz) => {
ty::TyArray(typ.fold_with(this), sz)
}
+ ty::TySlice(typ) => {
+ ty::TySlice(typ.fold_with(this))
+ }
ty::TyEnum(tid, ref substs) => {
let substs = substs.fold_with(this);
ty::TyEnum(tid, this.tcx().mk_substs(substs))
Ok(ty::mk_rptr(tcx, tcx.mk_region(r), mt))
}
- (&ty::TyArray(a_t, Some(sz_a)), &ty::TyArray(b_t, Some(sz_b))) =>
+ (&ty::TyArray(a_t, sz_a), &ty::TyArray(b_t, sz_b)) =>
{
let t = try!(relation.relate(&a_t, &b_t));
if sz_a == sz_b {
}
}
- (&ty::TyArray(a_t, None), &ty::TyArray(b_t, None)) =>
+ (&ty::TySlice(a_t), &ty::TySlice(b_t)) =>
{
let t = try!(relation.relate(&a_t, &b_t));
Ok(ty::mk_vec(tcx, t, None))
ty::TyBool | ty::TyChar | ty::TyInt(_) | ty::TyUint(_) | ty::TyFloat(_) |
ty::TyStr | ty::TyInfer(_) | ty::TyParam(_) | ty::TyError => {
}
- ty::TyBox(ty) | ty::TyArray(ty, _) => {
+ ty::TyBox(ty) | ty::TyArray(ty, _) | ty::TySlice(ty) => {
stack.push(ty);
}
ty::TyRawPtr(ref mt) | ty::TyRef(_, ref mt) => {
use middle::ty::{ReSkolemized, ReVar, BrEnv};
use middle::ty::{mt, Ty, ParamTy};
use middle::ty::{TyBool, TyChar, TyStruct, TyEnum};
-use middle::ty::{TyError, TyStr, TyArray, TyFloat, TyBareFn};
+use middle::ty::{TyError, TyStr, TyArray, TySlice, TyFloat, TyBareFn};
use middle::ty::{TyParam, TyRawPtr, TyRef, TyTuple};
use middle::ty::TyClosure;
use middle::ty::{TyBox, TyTrait, TyInt, TyUint, TyInfer};
})
}
TyArray(t, sz) => {
- let inner_str = ty_to_string(cx, t);
- match sz {
- Some(n) => format!("[{}; {}]", inner_str, n),
- None => format!("[{}]", inner_str),
- }
+ format!("[{}; {}]", ty_to_string(cx, t), sz)
+ }
+ TySlice(t) => {
+ format!("[{}]", ty_to_string(cx, t))
}
}
}
match rhs_t.sty {
ty::TyRef(_, mt) => match mt.ty.sty {
ty::TyStr => compare_str(cx, lhs, rhs, rhs_t, debug_loc),
- ty::TyArray(ty, _) => match ty.sty {
+ ty::TyArray(ty, _) | ty::TySlice(ty) => match ty.sty {
ty::TyUint(ast::TyU8) => {
// NOTE: cast &[u8] and &[u8; N] to &str and abuse the str_eq lang item,
// which calls memcmp().
Some(vec!(Load(bcx, val)))
} else {
match left_ty.sty {
- ty::TyArray(_, Some(n)) => {
+ ty::TyArray(_, n) => {
let args = extract_vec_elems(bcx, left_ty, n, 0, val);
Some(args.vals)
}
// Is this a fixed-size array of something non-zero
// with at least one element?
- ty::TyArray(ety, Some(d)) if d > 0 => {
+ ty::TyArray(ety, d) if d > 0 => {
if let Some(mut vpath) = find_discr_field_candidate(tcx, ety, path) {
vpath.push(0);
Some(vpath)
cx = f(cx, llupvar, upvar.ty);
}
}
- ty::TyArray(_, Some(n)) => {
+ ty::TyArray(_, n) => {
let (base, len) = tvec::get_fixed_base_and_len(cx, data_ptr, n);
let unit_ty = ty::sequence_element_type(cx.tcx(), t);
cx = tvec::iter_vec_raw(cx, base, unit_ty, len, f);
}
- ty::TyArray(_, None) | ty::TyStr => {
+ ty::TySlice(_) | ty::TyStr => {
let unit_ty = ty::sequence_element_type(cx.tcx(), t);
cx = tvec::iter_vec_raw(cx, data_ptr, unit_ty, info.unwrap(), f);
}
return false;
}
match ty.sty {
- ty::TyStruct(..) | ty::TyEnum(..) | ty::TyTuple(..) | ty::TyArray(_, Some(_)) |
+ ty::TyStruct(..) | ty::TyEnum(..) | ty::TyTuple(..) | ty::TyArray(_, _) |
ty::TyClosure(..) => {
let llty = sizing_type_of(ccx, ty);
llsize_of_alloc(ccx, llty) <= llsize_of_alloc(ccx, ccx.int_type())
"index is not an integer-constant expression")
};
let (arr, len) = match bt.sty {
- ty::TyArray(_, Some(u)) => (bv, C_uint(cx, u)),
- ty::TyArray(_, None) | ty::TyStr => {
+ ty::TyArray(_, u) => (bv, C_uint(cx, u)),
+ ty::TySlice(_) | ty::TyStr => {
let e1 = const_get_elt(cx, bv, &[0]);
(const_deref_ptr(cx, e1), const_get_elt(cx, bv, &[1]))
}
ty::TyRef(_, mt) => match mt.ty.sty {
- ty::TyArray(_, Some(u)) => {
+ ty::TyArray(_, u) => {
(const_deref_ptr(cx, bv), C_uint(cx, u))
},
_ => cx.sess().span_bug(base.span,
let inner_type_id = self.get_unique_type_id_as_string(inner_type_id);
unique_type_id.push_str(&inner_type_id[..]);
},
- ty::TyArray(inner_type, optional_length) => {
- match optional_length {
- Some(len) => {
- unique_type_id.push_str(&format!("[{}]", len));
- }
- None => {
- unique_type_id.push_str("[]");
- }
- };
+ ty::TyArray(inner_type, len) => {
+ unique_type_id.push_str(&format!("[{}]", len));
+
+ let inner_type_id = self.get_unique_type_id_of_type(cx, inner_type);
+ let inner_type_id = self.get_unique_type_id_as_string(inner_type_id);
+ unique_type_id.push_str(&inner_type_id[..]);
+ },
+ ty::TySlice(inner_type) => {
+ unique_type_id.push_str("[]");
let inner_type_id = self.get_unique_type_id_of_type(cx, inner_type);
let inner_type_id = self.get_unique_type_id_as_string(inner_type_id);
prepare_enum_metadata(cx, t, def_id, unique_type_id, usage_site_span).finalize(cx)
}
ty::TyArray(typ, len) => {
- fixed_vec_metadata(cx, unique_type_id, typ, len.map(|x| x 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)
}
ty::TyStr => {
fixed_vec_metadata(cx, unique_type_id, cx.tcx().types.i8, None, usage_site_span)
}
ty::TyBox(ty) | ty::TyRawPtr(ty::mt{ty, ..}) | ty::TyRef(_, ty::mt{ty, ..}) => {
match ty.sty {
- ty::TyArray(typ, None) => {
+ ty::TySlice(typ) => {
vec_slice_metadata(cx, t, typ, unique_type_id, usage_site_span)
}
ty::TyStr => {
push_debuginfo_type_name(cx, inner_type, true, output);
},
- ty::TyArray(inner_type, optional_length) => {
+ ty::TyArray(inner_type, len) => {
+ output.push('[');
+ push_debuginfo_type_name(cx, inner_type, true, output);
+ output.push_str(&format!("; {}", len));
+ output.push(']');
+ },
+ ty::TySlice(inner_type) => {
output.push('[');
push_debuginfo_type_name(cx, inner_type, true, output);
-
- match optional_length {
- Some(len) => {
- output.push_str(&format!("; {}", len));
- }
- None => { /* nothing to do */ }
- };
-
output.push(']');
},
ty::TyTrait(ref trait_data) => {
-> ValueRef {
let (source, target) = ty::struct_lockstep_tails(ccx.tcx(), source, target);
match (&source.sty, &target.sty) {
- (&ty::TyArray(_, Some(len)), &ty::TyArray(_, None)) => C_uint(ccx, len),
+ (&ty::TyArray(_, len), &ty::TySlice(_)) => C_uint(ccx, len),
(&ty::TyTrait(_), &ty::TyTrait(_)) => {
// For now, upcasts are limited to changes in marker
// traits, and hence never actually require an actual
let align_ptr = GEPi(bcx, info, &[2]);
(Load(bcx, size_ptr), Load(bcx, align_ptr))
}
- ty::TyArray(_, None) | ty::TyStr => {
+ ty::TySlice(_) | ty::TyStr => {
let unit_ty = ty::sequence_element_type(bcx.tcx(), t);
// The info in this case is the length of the str, so the size is that
// times the unit size.
let ccx = bcx.ccx();
match vec_ty.sty {
- ty::TyArray(_, Some(n)) => get_fixed_base_and_len(bcx, llval, n),
- ty::TyArray(_, None) | ty::TyStr => {
+ ty::TyArray(_, n) => get_fixed_base_and_len(bcx, llval, n),
+ ty::TySlice(_) | ty::TyStr => {
let base = Load(bcx, expr::get_dataptr(bcx, llval));
let len = Load(bcx, expr::get_len(bcx, llval));
(base, len)
ty::TyBareFn(..) => Type::i8p(cx),
- ty::TyArray(ty, Some(size)) => {
+ ty::TyArray(ty, size) => {
let llty = sizing_type_of(cx, ty);
let size = size as u64;
ensure_array_fits_in_address_space(cx, llty, size, t);
cx.sess().bug(&format!("fictitious type {} in sizing_type_of()",
ppaux::ty_to_string(cx.tcx(), t)))
}
- ty::TyArray(_, None) | ty::TyTrait(..) | ty::TyStr => unreachable!()
+ ty::TySlice(_) | ty::TyTrait(..) | ty::TyStr => unreachable!()
};
cx.llsizingtypes().borrow_mut().insert(t, llsizingty);
let ptr_ty = in_memory_type_of(cx, ty).ptr_to();
let unsized_part = ty::struct_tail(cx.tcx(), ty);
let info_ty = match unsized_part.sty {
- ty::TyStr | ty::TyArray(..) => {
+ ty::TyStr | ty::TyArray(..) | ty::TySlice(_) => {
Type::uint_from_ty(cx, ast::TyUs)
}
ty::TyTrait(_) => Type::vtable_ptr(cx),
}
}
- ty::TyArray(ty, Some(size)) => {
+ ty::TyArray(ty, size) => {
let size = size as u64;
let llty = in_memory_type_of(cx, ty);
ensure_array_fits_in_address_space(cx, llty, size, t);
// traits have the type of u8. This is so that the data pointer inside
// fat pointers is of the right type (e.g. for array accesses), even
// when taking the address of an unsized field in a struct.
- ty::TyArray(ty, None) => in_memory_type_of(cx, ty),
+ ty::TySlice(ty) => in_memory_type_of(cx, ty),
ty::TyStr | ty::TyTrait(..) => Type::i8(cx),
ty::TyBareFn(..) => {
if let ast::LitBinary(_) = lt.node {
let expected_ty = structurally_resolved_type(fcx, pat.span, expected);
if let ty::TyRef(_, mt) = expected_ty.sty {
- if let ty::TyArray(_, None) = mt.ty.sty {
+ if let ty::TySlice(_) = mt.ty.sty {
pat_ty = ty::mk_slice(tcx, tcx.mk_region(ty::ReStatic),
ty::mt{ ty: tcx.types.u8, mutbl: ast::MutImmutable })
}
let expected_ty = structurally_resolved_type(fcx, pat.span, expected);
let inner_ty = fcx.infcx().next_ty_var();
let pat_ty = match expected_ty.sty {
- ty::TyArray(_, Some(size)) => ty::mk_vec(tcx, inner_ty, Some({
+ ty::TyArray(_, size) => ty::mk_vec(tcx, inner_ty, Some({
let min_len = before.len() + after.len();
match *slice {
Some(_) => cmp::max(min_len, size),
t: Ty<'tcx>)
-> Option<UnsizeKind<'tcx>> {
match t.sty {
- ty::TyArray(_, None) | ty::TyStr => Some(UnsizeKind::Length),
+ ty::TySlice(_) | ty::TyStr => Some(UnsizeKind::Length),
ty::TyTrait(_) => Some(UnsizeKind::Vtable),
ty::TyStruct(did, substs) => {
match ty::struct_fields(fcx.tcx(), did, substs).pop() {
// array-ptr-cast.
if m_expr.mutbl == ast::MutImmutable && m_cast.mutbl == ast::MutImmutable {
- if let ty::TyArray(ety, Some(_)) = m_expr.ty.sty {
+ if let ty::TyArray(ety, _) = m_expr.ty.sty {
// Due to the limitations of LLVM global constants,
// region pointers end up pointing at copies of
// vector elements instead of the original values.
});
match final_ty.sty {
- ty::TyArray(elem_ty, Some(_)) => {
+ ty::TyArray(elem_ty, _) => {
let slice_ty = ty::mk_vec(fcx.tcx(), elem_ty, None);
steps.push(CandidateStep {
self_ty: slice_ty,
let lang_def_id = self.tcx().lang_items.str_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
- ty::TyArray(_, None) => {
+ ty::TySlice(_) => {
let lang_def_id = self.tcx().lang_items.slice_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
// After we have fully autoderef'd, if the resulting type is [T; n], then
// do a final unsized coercion to yield [T].
- if let ty::TyArray(element_ty, Some(_)) = ty.sty {
+ if let ty::TyArray(element_ty, _) = ty.sty {
let adjusted_ty = ty::mk_vec(fcx.tcx(), element_ty, None);
try_index_step(fcx, MethodCall::expr(expr.id), expr, base_expr,
adjusted_ty, autoderefs, true, lvalue_pref, idx_ty)
ast::ExprVec(ref args) => {
let uty = expected.to_option(fcx).and_then(|uty| {
match uty.sty {
- ty::TyArray(ty, _) => Some(ty),
+ ty::TyArray(ty, _) | ty::TySlice(ty) => Some(ty),
_ => None
}
});
let uty = match expected {
ExpectHasType(uty) => {
match uty.sty {
- ty::TyArray(ty, _) => Some(ty),
+ ty::TyArray(ty, _) | ty::TySlice(ty) => Some(ty),
_ => None
}
}
/// for examples of where this comes up,.
fn rvalue_hint(ty: Ty<'tcx>) -> Expectation<'tcx> {
match ty.sty {
- ty::TyArray(_, None) | ty::TyTrait(..) => {
+ ty::TySlice(_) | ty::TyTrait(..) => {
ExpectRvalueLikeUnsized(ty)
}
_ => ExpectHasType(ty)
let r_index_expr = ty::ReScope(CodeExtent::from_node_id(index_expr.id));
if let ty::TyRef(r_ptr, mt) = indexed_ty.sty {
match mt.ty.sty {
- ty::TyArray(_, None) | ty::TyStr => {
+ ty::TySlice(_) | ty::TyStr => {
rcx.fcx.mk_subr(infer::IndexSlice(index_expr.span),
r_index_expr, *r_ptr);
}
use middle::ty::{Ty, TyBool, TyChar, TyEnum, TyError};
use middle::ty::{TyParam, TypeScheme, TyRawPtr};
use middle::ty::{TyRef, TyStruct, TyTrait, TyTuple};
-use middle::ty::{TyStr, TyArray, TyFloat, TyInfer, TyInt};
+use middle::ty::{TyStr, TyArray, TySlice, TyFloat, TyInfer, TyInt};
use middle::ty::{TyUint, TyClosure, TyBox, TyBareFn};
use middle::ty::TyProjection;
use middle::ty;
}
TyBool | TyChar | TyInt(..) | TyUint(..) | TyFloat(..) |
- TyStr(..) | TyArray(..) | TyBareFn(..) | TyTuple(..) |
+ TyStr(..) | TyArray(..) | TySlice(..) | TyBareFn(..) | TyTuple(..) |
TyParam(..) | TyError |
TyRawPtr(_) | TyRef(_, _) | TyProjection(..) => {
None
"str",
item.span);
}
- ty::TyArray(_, None) => {
+ ty::TySlice(_) => {
self.check_primitive_impl(def_id,
self.tcx.lang_items.slice_impl(),
"slice",
self.add_constraints_from_mt(generics, mt, variance);
}
- ty::TyBox(typ) | ty::TyArray(typ, _) => {
+ ty::TyBox(typ) | ty::TyArray(typ, _) | ty::TySlice(typ) => {
self.add_constraints_from_ty(generics, typ, variance);
}
});
lang_struct(cx, box_did, t, "Box", Unique)
}
- ty::TyArray(ty, None) => Vector(box ty.clean(cx)),
- ty::TyArray(ty, Some(i)) => FixedVector(box ty.clean(cx),
- format!("{}", i)),
+ ty::TySlice(ty) => Vector(box ty.clean(cx)),
+ ty::TyArray(ty, i) => FixedVector(box ty.clean(cx),
+ format!("{}", i)),
ty::TyRawPtr(mt) => RawPointer(mt.mutbl.clean(cx), box mt.ty.clean(cx)),
ty::TyRef(r, mt) => BorrowedRef {
lifetime: r.clean(cx),