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