libsyntax: clearer names for some AST parts
This applies the HIR changes from the previous commits to the AST, and is thus a syntax-[breaking-change] Renames `PatKind::Vec` to `PatKind::Slice`, since these are called slice patterns, not vec patterns. Renames `TyKind::Vec`, which represents the type `[T]`, to `TyKind::Slice`. Renames `TyKind::FixedLengthVec` to `TyKind::Array`.
This commit is contained in:
parent
cf0b7bdd0c
commit
48e5199de3
11 changed files with 42 additions and 43 deletions
|
@ -222,17 +222,16 @@ impl<'a> LoweringContext<'a> {
|
|||
}
|
||||
|
||||
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),
|
||||
|
@ -240,12 +239,12 @@ impl<'a> LoweringContext<'a> {
|
|||
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),
|
||||
|
@ -254,22 +253,22 @@ impl<'a> LoweringContext<'a> {
|
|||
});
|
||||
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,
|
||||
})
|
||||
|
@ -891,7 +890,7 @@ impl<'a> LoweringContext<'a> {
|
|||
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())
|
||||
|
|
|
@ -286,7 +286,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -593,7 +593,7 @@ impl Pat {
|
|||
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))
|
||||
|
@ -669,8 +669,8 @@ pub enum PatKind {
|
|||
/// 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),
|
||||
}
|
||||
|
@ -1431,10 +1431,10 @@ pub struct BareFnTy {
|
|||
/// 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`)
|
||||
|
|
|
@ -215,7 +215,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
|
|||
|
||||
let ty = ecx.ty(
|
||||
span,
|
||||
ast::TyKind::FixedLengthVec(
|
||||
ast::TyKind::Array(
|
||||
ecx.ty(
|
||||
span,
|
||||
ast::TyKind::Tup(vec![ty_str.clone(), ty_str])
|
||||
|
|
|
@ -1082,14 +1082,14 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
|
|||
|
||||
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");
|
||||
|
|
|
@ -356,7 +356,7 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
|
|||
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))
|
||||
|
@ -385,8 +385,8 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
|
|||
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))
|
||||
|
@ -1092,8 +1092,8 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
|
|||
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)))
|
||||
}
|
||||
|
|
|
@ -1386,8 +1386,8 @@ impl<'a> Parser<'a> {
|
|||
// 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
|
||||
|
@ -3587,7 +3587,7 @@ impl<'a> Parser<'a> {
|
|||
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) {
|
||||
|
|
|
@ -972,7 +972,7 @@ impl<'a> State<'a> {
|
|||
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, "]"));
|
||||
|
@ -1039,7 +1039,7 @@ impl<'a> State<'a> {
|
|||
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, "; "));
|
||||
|
@ -2573,7 +2573,7 @@ impl<'a> State<'a> {
|
|||
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[..],
|
||||
|
|
|
@ -564,7 +564,7 @@ fn mk_tests(cx: &TestCtxt) -> P<ast::Item> {
|
|||
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 = &[...];
|
||||
|
|
|
@ -313,7 +313,7 @@ pub fn walk_variant<V>(visitor: &mut V, variant: &Variant, generics: &Generics,
|
|||
|
||||
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) => {
|
||||
|
@ -341,7 +341,7 @@ pub fn walk_ty<V: Visitor>(visitor: &mut V, typ: &Ty) {
|
|||
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)
|
||||
}
|
||||
|
@ -434,7 +434,7 @@ pub fn walk_pat<V: Visitor>(visitor: &mut V, pattern: &Pat) {
|
|||
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);
|
||||
|
|
|
@ -506,7 +506,7 @@ impl<'a, 'b> Context<'a, 'b> {
|
|||
-> 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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue