}
fn lower_ty(&mut self, t: &Ty) -> P<hir::Ty> {
- use syntax::ast::TyKind::*;
P(hir::Ty {
id: t.id,
node: match t.node {
- Infer | ImplicitSelf => hir::TyInfer,
- Vec(ref ty) => hir::TySlice(self.lower_ty(ty)),
- Ptr(ref mt) => hir::TyPtr(self.lower_mt(mt)),
- Rptr(ref region, ref mt) => {
+ TyKind::Infer | TyKind::ImplicitSelf => hir::TyInfer,
+ TyKind::Slice(ref ty) => hir::TySlice(self.lower_ty(ty)),
+ TyKind::Ptr(ref mt) => hir::TyPtr(self.lower_mt(mt)),
+ TyKind::Rptr(ref region, ref mt) => {
hir::TyRptr(self.lower_opt_lifetime(region), self.lower_mt(mt))
}
- BareFn(ref f) => {
+ TyKind::BareFn(ref f) => {
hir::TyBareFn(P(hir::BareFnTy {
lifetimes: self.lower_lifetime_defs(&f.lifetimes),
unsafety: self.lower_unsafety(f.unsafety),
decl: self.lower_fn_decl(&f.decl),
}))
}
- Never => hir::TyNever,
- Tup(ref tys) => hir::TyTup(tys.iter().map(|ty| self.lower_ty(ty)).collect()),
- Paren(ref ty) => {
+ TyKind::Never => hir::TyNever,
+ TyKind::Tup(ref tys) => hir::TyTup(tys.iter().map(|ty| self.lower_ty(ty)).collect()),
+ TyKind::Paren(ref ty) => {
return self.lower_ty(ty);
}
- Path(ref qself, ref path) => {
+ TyKind::Path(ref qself, ref path) => {
let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
hir::QSelf {
ty: self.lower_ty(ty),
});
hir::TyPath(qself, self.lower_path(path))
}
- ObjectSum(ref ty, ref bounds) => {
+ TyKind::ObjectSum(ref ty, ref bounds) => {
hir::TyObjectSum(self.lower_ty(ty), self.lower_bounds(bounds))
}
- FixedLengthVec(ref ty, ref e) => {
+ TyKind::Array(ref ty, ref e) => {
hir::TyArray(self.lower_ty(ty), self.lower_expr(e))
}
- Typeof(ref expr) => {
+ TyKind::Typeof(ref expr) => {
hir::TyTypeof(self.lower_expr(expr))
}
- PolyTraitRef(ref bounds) => {
+ TyKind::PolyTraitRef(ref bounds) => {
hir::TyPolyTraitRef(self.lower_bounds(bounds))
}
- ImplTrait(ref bounds) => {
+ TyKind::ImplTrait(ref bounds) => {
hir::TyImplTrait(self.lower_bounds(bounds))
}
- Mac(_) => panic!("TyMac should have been expanded by now."),
+ TyKind::Mac(_) => panic!("TyMac should have been expanded by now."),
},
span: t.span,
})
PatKind::Range(ref e1, ref e2) => {
hir::PatKind::Range(self.lower_expr(e1), self.lower_expr(e2))
}
- PatKind::Vec(ref before, ref slice, ref after) => {
+ PatKind::Slice(ref before, ref slice, ref after) => {
hir::PatKind::Slice(before.iter().map(|x| self.lower_pat(x)).collect(),
slice.as_ref().map(|x| self.lower_pat(x)),
after.iter().map(|x| self.lower_pat(x)).collect())
fn visit_ty(&mut self, ty: &Ty) {
match ty.node {
TyKind::Mac(..) => return self.visit_macro_invoc(ty.id, false),
- TyKind::FixedLengthVec(_, ref length) => self.visit_ast_const_integer(length),
+ TyKind::Array(_, ref length) => self.visit_ast_const_integer(length),
TyKind::ImplTrait(..) => {
self.create_def(ty.id, DefPathData::ImplTrait);
}
PatKind::Box(ref s) | PatKind::Ref(ref s, _) => {
s.walk(it)
}
- PatKind::Vec(ref before, ref slice, ref after) => {
+ PatKind::Slice(ref before, ref slice, ref after) => {
before.iter().all(|p| p.walk(it)) &&
slice.iter().all(|p| p.walk(it)) &&
after.iter().all(|p| p.walk(it))
/// A range pattern, e.g. `1...2`
Range(P<Expr>, P<Expr>),
/// `[a, b, ..i, y, z]` is represented as:
- /// `PatKind::Vec(box [a, b], Some(i), box [y, z])`
- Vec(Vec<P<Pat>>, Option<P<Pat>>, Vec<P<Pat>>),
+ /// `PatKind::Slice(box [a, b], Some(i), box [y, z])`
+ Slice(Vec<P<Pat>>, Option<P<Pat>>, Vec<P<Pat>>),
/// A macro pattern; pre-expansion
Mac(Mac),
}
/// The different kinds of types recognized by the compiler
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum TyKind {
- /// A variable-length array (`[T]`)
- Vec(P<Ty>),
+ /// A variable-length slice (`[T]`)
+ Slice(P<Ty>),
/// A fixed length array (`[T; n]`)
- FixedLengthVec(P<Ty>, P<Expr>),
+ Array(P<Ty>, P<Expr>),
/// A raw pointer (`*const T` or `*mut T`)
Ptr(MutTy),
/// A reference (`&'a T` or `&'a mut T`)
let ty = ecx.ty(
span,
- ast::TyKind::FixedLengthVec(
+ ast::TyKind::Array(
ecx.ty(
span,
ast::TyKind::Tup(vec![ty_str.clone(), ty_str])
fn visit_pat(&mut self, pattern: &ast::Pat) {
match pattern.node {
- PatKind::Vec(_, Some(_), ref last) if !last.is_empty() => {
+ PatKind::Slice(_, Some(_), ref last) if !last.is_empty() => {
gate_feature_post!(&self, advanced_slice_patterns,
pattern.span,
"multiple-element slice matches anywhere \
but at the end of a slice (e.g. \
`[0, ..xs, 0]`) are experimental")
}
- PatKind::Vec(..) => {
+ PatKind::Slice(..) => {
gate_feature_post!(&self, slice_patterns,
pattern.span,
"slice pattern syntax is experimental");
id: fld.new_id(id),
node: match node {
TyKind::Infer | TyKind::ImplicitSelf => node,
- TyKind::Vec(ty) => TyKind::Vec(fld.fold_ty(ty)),
+ TyKind::Slice(ty) => TyKind::Slice(fld.fold_ty(ty)),
TyKind::Ptr(mt) => TyKind::Ptr(fld.fold_mt(mt)),
TyKind::Rptr(region, mt) => {
TyKind::Rptr(fld.fold_opt_lifetime(region), fld.fold_mt(mt))
TyKind::ObjectSum(fld.fold_ty(ty),
fld.fold_bounds(bounds))
}
- TyKind::FixedLengthVec(ty, e) => {
- TyKind::FixedLengthVec(fld.fold_ty(ty), fld.fold_expr(e))
+ TyKind::Array(ty, e) => {
+ TyKind::Array(fld.fold_ty(ty), fld.fold_expr(e))
}
TyKind::Typeof(expr) => {
TyKind::Typeof(fld.fold_expr(expr))
PatKind::Range(e1, e2) => {
PatKind::Range(folder.fold_expr(e1), folder.fold_expr(e2))
},
- PatKind::Vec(before, slice, after) => {
- PatKind::Vec(before.move_map(|x| folder.fold_pat(x)),
+ PatKind::Slice(before, slice, after) => {
+ PatKind::Slice(before.move_map(|x| folder.fold_pat(x)),
slice.map(|x| folder.fold_pat(x)),
after.move_map(|x| folder.fold_pat(x)))
}
// Parse the `; e` in `[ i32; e ]`
// where `e` is a const expression
let t = match self.maybe_parse_fixed_length_of_vec()? {
- None => TyKind::Vec(t),
- Some(suffix) => TyKind::FixedLengthVec(t, suffix)
+ None => TyKind::Slice(t),
+ Some(suffix) => TyKind::Array(t, suffix)
};
self.expect(&token::CloseDelim(token::Bracket))?;
t
self.bump();
let (before, slice, after) = self.parse_pat_vec_elements()?;
self.expect(&token::CloseDelim(token::Bracket))?;
- pat = PatKind::Vec(before, slice, after);
+ pat = PatKind::Slice(before, slice, after);
}
// At this point, token != _, &, &&, (, [
_ => if self.eat_keyword(keywords::Mut) {
try!(self.maybe_print_comment(ty.span.lo));
try!(self.ibox(0));
match ty.node {
- ast::TyKind::Vec(ref ty) => {
+ ast::TyKind::Slice(ref ty) => {
try!(word(&mut self.s, "["));
try!(self.print_type(&ty));
try!(word(&mut self.s, "]"));
ast::TyKind::ImplTrait(ref bounds) => {
try!(self.print_bounds("impl ", &bounds[..]));
}
- ast::TyKind::FixedLengthVec(ref ty, ref v) => {
+ ast::TyKind::Array(ref ty, ref v) => {
try!(word(&mut self.s, "["));
try!(self.print_type(&ty));
try!(word(&mut self.s, "; "));
try!(word(&mut self.s, "..."));
try!(self.print_expr(&end));
}
- PatKind::Vec(ref before, ref slice, ref after) => {
+ PatKind::Slice(ref before, ref slice, ref after) => {
try!(word(&mut self.s, "["));
try!(self.commasep(Inconsistent,
&before[..],
let static_lt = ecx.lifetime(sp, keywords::StaticLifetime.name());
// &'static [self::test::TestDescAndFn]
let static_type = ecx.ty_rptr(sp,
- ecx.ty(sp, ast::TyKind::Vec(struct_type)),
+ ecx.ty(sp, ast::TyKind::Slice(struct_type)),
Some(static_lt),
ast::Mutability::Immutable);
// static TESTS: $static_type = &[...];
pub fn walk_ty<V: Visitor>(visitor: &mut V, typ: &Ty) {
match typ.node {
- TyKind::Vec(ref ty) | TyKind::Paren(ref ty) => {
+ TyKind::Slice(ref ty) | TyKind::Paren(ref ty) => {
visitor.visit_ty(ty)
}
TyKind::Ptr(ref mutable_type) => {
visitor.visit_ty(ty);
walk_list!(visitor, visit_ty_param_bound, bounds);
}
- TyKind::FixedLengthVec(ref ty, ref expression) => {
+ TyKind::Array(ref ty, ref expression) => {
visitor.visit_ty(ty);
visitor.visit_expr(expression)
}
visitor.visit_expr(upper_bound)
}
PatKind::Wild => (),
- PatKind::Vec(ref prepatterns, ref slice_pattern, ref postpatterns) => {
+ PatKind::Slice(ref prepatterns, ref slice_pattern, ref postpatterns) => {
walk_list!(visitor, visit_pat, prepatterns);
walk_list!(visitor, visit_pat, slice_pattern);
walk_list!(visitor, visit_pat, postpatterns);
-> P<ast::Expr> {
let sp = piece_ty.span;
let ty = ecx.ty_rptr(sp,
- ecx.ty(sp, ast::TyKind::Vec(piece_ty)),
+ ecx.ty(sp, ast::TyKind::Slice(piece_ty)),
Some(ecx.lifetime(sp, keywords::StaticLifetime.name())),
ast::Mutability::Immutable);
let slice = ecx.expr_vec_slice(sp, pieces);