Skip to content

Commit

Permalink
Auto merge of rust-lang#26267 - eefriedman:split-tyarray, r=eddyb
Browse files Browse the repository at this point in the history
Arrays and slices are closely related, but not that closely; making the
separation more explicit is generally more clear.
  • Loading branch information
bors committed Jun 13, 2015
2 parents a9f1e29 + 33b7386 commit a279826
Show file tree
Hide file tree
Showing 34 changed files with 138 additions and 150 deletions.
11 changes: 6 additions & 5 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ pub fn enc_ty<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx>) {
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");
Expand Down
12 changes: 8 additions & 4 deletions src/librustc/middle/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
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.
Expand Down Expand Up @@ -851,10 +851,14 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'tcx> {
}
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,
_ => {}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,14 +537,14 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,

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!())
Expand All @@ -560,7 +560,7 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
}
}

ty::TyArray(_, Some(len)) => {
ty::TyArray(_, len) => {
assert_eq!(pats_len, len);
ast::PatVec(pats.collect(), None, vec![])
}
Expand Down Expand Up @@ -601,7 +601,7 @@ fn all_constructors(cx: &MatchCheckCtxt, left_ty: Ty,
[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)
},
Expand Down Expand Up @@ -779,7 +779,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
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))
Expand Down Expand Up @@ -807,7 +807,7 @@ pub fn constructor_arity(cx: &MatchCheckCtxt, ctor: &Constructor, ty: Ty) -> usi
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!()
Expand All @@ -822,7 +822,7 @@ pub fn constructor_arity(cx: &MatchCheckCtxt, ctor: &Constructor, ty: Ty) -> usi
}
}
ty::TyStruct(cid, _) => ty::lookup_struct_fields(cx.tcx, cid).len(),
ty::TyArray(_, Some(n)) => n,
ty::TyArray(_, n) => n,
_ => 0
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/fast_reject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn simplify_type(tcx: &ty::ctxt,
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()))
Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/implicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ impl<'a, 'tcx> Implicator<'a, 'tcx> {
}

ty::TyArray(t, _) |
ty::TySlice(t) |
ty::TyRawPtr(ty::mt { ty: t, .. }) |
ty::TyBox(t) => {
self.accumulate_from_ty(t)
Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/infer/freshen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
ty::TyStr |
ty::TyError |
ty::TyArray(..) |
ty::TySlice(..) |
ty::TyRawPtr(..) |
ty::TyRef(..) |
ty::TyBareFn(..) |
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ fn deref_kind(t: Ty, context: DerefKindContext) -> McResult<deref_kind> {
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))))
Expand Down Expand Up @@ -843,7 +843,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
// 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
};

Expand Down Expand Up @@ -1130,7 +1130,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
-> (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),
},

Expand Down Expand Up @@ -1669,10 +1669,10 @@ fn element_kind(t: Ty) -> ElementKind {
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
}
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ fn ty_is_local_constructor<'tcx>(tcx: &ty::ctxt<'tcx>,
ty::TyStr(..) |
ty::TyBareFn(..) |
ty::TyArray(..) |
ty::TySlice(..) |
ty::TyRawPtr(..) |
ty::TyRef(..) |
ty::TyTuple(..) |
Expand Down
33 changes: 8 additions & 25 deletions src/librustc/middle/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}

// [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, _)) => {
Expand Down Expand Up @@ -1662,35 +1662,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
}

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()");
Expand Down Expand Up @@ -1855,7 +1838,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
Some(vec![element_ty])
},

ty::TyArray(element_ty, _) => {
ty::TyArray(element_ty, _) | ty::TySlice(element_ty) => {
Some(vec![element_ty])
}

Expand Down Expand Up @@ -2510,7 +2493,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}

// [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);
Expand Down
Loading

0 comments on commit a279826

Please sign in to comment.