Skip to content

Commit 48e5199

Browse files
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`.
1 parent cf0b7bd commit 48e5199

File tree

11 files changed

+42
-43
lines changed

11 files changed

+42
-43
lines changed

src/librustc/hir/lowering.rs

+16-17
Original file line numberDiff line numberDiff line change
@@ -222,30 +222,29 @@ impl<'a> LoweringContext<'a> {
222222
}
223223

224224
fn lower_ty(&mut self, t: &Ty) -> P<hir::Ty> {
225-
use syntax::ast::TyKind::*;
226225
P(hir::Ty {
227226
id: t.id,
228227
node: match t.node {
229-
Infer | ImplicitSelf => hir::TyInfer,
230-
Vec(ref ty) => hir::TySlice(self.lower_ty(ty)),
231-
Ptr(ref mt) => hir::TyPtr(self.lower_mt(mt)),
232-
Rptr(ref region, ref mt) => {
228+
TyKind::Infer | TyKind::ImplicitSelf => hir::TyInfer,
229+
TyKind::Slice(ref ty) => hir::TySlice(self.lower_ty(ty)),
230+
TyKind::Ptr(ref mt) => hir::TyPtr(self.lower_mt(mt)),
231+
TyKind::Rptr(ref region, ref mt) => {
233232
hir::TyRptr(self.lower_opt_lifetime(region), self.lower_mt(mt))
234233
}
235-
BareFn(ref f) => {
234+
TyKind::BareFn(ref f) => {
236235
hir::TyBareFn(P(hir::BareFnTy {
237236
lifetimes: self.lower_lifetime_defs(&f.lifetimes),
238237
unsafety: self.lower_unsafety(f.unsafety),
239238
abi: f.abi,
240239
decl: self.lower_fn_decl(&f.decl),
241240
}))
242241
}
243-
Never => hir::TyNever,
244-
Tup(ref tys) => hir::TyTup(tys.iter().map(|ty| self.lower_ty(ty)).collect()),
245-
Paren(ref ty) => {
242+
TyKind::Never => hir::TyNever,
243+
TyKind::Tup(ref tys) => hir::TyTup(tys.iter().map(|ty| self.lower_ty(ty)).collect()),
244+
TyKind::Paren(ref ty) => {
246245
return self.lower_ty(ty);
247246
}
248-
Path(ref qself, ref path) => {
247+
TyKind::Path(ref qself, ref path) => {
249248
let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
250249
hir::QSelf {
251250
ty: self.lower_ty(ty),
@@ -254,22 +253,22 @@ impl<'a> LoweringContext<'a> {
254253
});
255254
hir::TyPath(qself, self.lower_path(path))
256255
}
257-
ObjectSum(ref ty, ref bounds) => {
256+
TyKind::ObjectSum(ref ty, ref bounds) => {
258257
hir::TyObjectSum(self.lower_ty(ty), self.lower_bounds(bounds))
259258
}
260-
FixedLengthVec(ref ty, ref e) => {
259+
TyKind::Array(ref ty, ref e) => {
261260
hir::TyArray(self.lower_ty(ty), self.lower_expr(e))
262261
}
263-
Typeof(ref expr) => {
262+
TyKind::Typeof(ref expr) => {
264263
hir::TyTypeof(self.lower_expr(expr))
265264
}
266-
PolyTraitRef(ref bounds) => {
265+
TyKind::PolyTraitRef(ref bounds) => {
267266
hir::TyPolyTraitRef(self.lower_bounds(bounds))
268267
}
269-
ImplTrait(ref bounds) => {
268+
TyKind::ImplTrait(ref bounds) => {
270269
hir::TyImplTrait(self.lower_bounds(bounds))
271270
}
272-
Mac(_) => panic!("TyMac should have been expanded by now."),
271+
TyKind::Mac(_) => panic!("TyMac should have been expanded by now."),
273272
},
274273
span: t.span,
275274
})
@@ -891,7 +890,7 @@ impl<'a> LoweringContext<'a> {
891890
PatKind::Range(ref e1, ref e2) => {
892891
hir::PatKind::Range(self.lower_expr(e1), self.lower_expr(e2))
893892
}
894-
PatKind::Vec(ref before, ref slice, ref after) => {
893+
PatKind::Slice(ref before, ref slice, ref after) => {
895894
hir::PatKind::Slice(before.iter().map(|x| self.lower_pat(x)).collect(),
896895
slice.as_ref().map(|x| self.lower_pat(x)),
897896
after.iter().map(|x| self.lower_pat(x)).collect())

src/librustc/hir/map/def_collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
286286
fn visit_ty(&mut self, ty: &Ty) {
287287
match ty.node {
288288
TyKind::Mac(..) => return self.visit_macro_invoc(ty.id, false),
289-
TyKind::FixedLengthVec(_, ref length) => self.visit_ast_const_integer(length),
289+
TyKind::Array(_, ref length) => self.visit_ast_const_integer(length),
290290
TyKind::ImplTrait(..) => {
291291
self.create_def(ty.id, DefPathData::ImplTrait);
292292
}

src/libsyntax/ast.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ impl Pat {
593593
PatKind::Box(ref s) | PatKind::Ref(ref s, _) => {
594594
s.walk(it)
595595
}
596-
PatKind::Vec(ref before, ref slice, ref after) => {
596+
PatKind::Slice(ref before, ref slice, ref after) => {
597597
before.iter().all(|p| p.walk(it)) &&
598598
slice.iter().all(|p| p.walk(it)) &&
599599
after.iter().all(|p| p.walk(it))
@@ -669,8 +669,8 @@ pub enum PatKind {
669669
/// A range pattern, e.g. `1...2`
670670
Range(P<Expr>, P<Expr>),
671671
/// `[a, b, ..i, y, z]` is represented as:
672-
/// `PatKind::Vec(box [a, b], Some(i), box [y, z])`
673-
Vec(Vec<P<Pat>>, Option<P<Pat>>, Vec<P<Pat>>),
672+
/// `PatKind::Slice(box [a, b], Some(i), box [y, z])`
673+
Slice(Vec<P<Pat>>, Option<P<Pat>>, Vec<P<Pat>>),
674674
/// A macro pattern; pre-expansion
675675
Mac(Mac),
676676
}
@@ -1431,10 +1431,10 @@ pub struct BareFnTy {
14311431
/// The different kinds of types recognized by the compiler
14321432
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
14331433
pub enum TyKind {
1434-
/// A variable-length array (`[T]`)
1435-
Vec(P<Ty>),
1434+
/// A variable-length slice (`[T]`)
1435+
Slice(P<Ty>),
14361436
/// A fixed length array (`[T; n]`)
1437-
FixedLengthVec(P<Ty>, P<Expr>),
1437+
Array(P<Ty>, P<Expr>),
14381438
/// A raw pointer (`*const T` or `*mut T`)
14391439
Ptr(MutTy),
14401440
/// A reference (`&'a T` or `&'a mut T`)

src/libsyntax/diagnostics/plugin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
215215

216216
let ty = ecx.ty(
217217
span,
218-
ast::TyKind::FixedLengthVec(
218+
ast::TyKind::Array(
219219
ecx.ty(
220220
span,
221221
ast::TyKind::Tup(vec![ty_str.clone(), ty_str])

src/libsyntax/feature_gate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1082,14 +1082,14 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
10821082

10831083
fn visit_pat(&mut self, pattern: &ast::Pat) {
10841084
match pattern.node {
1085-
PatKind::Vec(_, Some(_), ref last) if !last.is_empty() => {
1085+
PatKind::Slice(_, Some(_), ref last) if !last.is_empty() => {
10861086
gate_feature_post!(&self, advanced_slice_patterns,
10871087
pattern.span,
10881088
"multiple-element slice matches anywhere \
10891089
but at the end of a slice (e.g. \
10901090
`[0, ..xs, 0]`) are experimental")
10911091
}
1092-
PatKind::Vec(..) => {
1092+
PatKind::Slice(..) => {
10931093
gate_feature_post!(&self, slice_patterns,
10941094
pattern.span,
10951095
"slice pattern syntax is experimental");

src/libsyntax/fold.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
356356
id: fld.new_id(id),
357357
node: match node {
358358
TyKind::Infer | TyKind::ImplicitSelf => node,
359-
TyKind::Vec(ty) => TyKind::Vec(fld.fold_ty(ty)),
359+
TyKind::Slice(ty) => TyKind::Slice(fld.fold_ty(ty)),
360360
TyKind::Ptr(mt) => TyKind::Ptr(fld.fold_mt(mt)),
361361
TyKind::Rptr(region, mt) => {
362362
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> {
385385
TyKind::ObjectSum(fld.fold_ty(ty),
386386
fld.fold_bounds(bounds))
387387
}
388-
TyKind::FixedLengthVec(ty, e) => {
389-
TyKind::FixedLengthVec(fld.fold_ty(ty), fld.fold_expr(e))
388+
TyKind::Array(ty, e) => {
389+
TyKind::Array(fld.fold_ty(ty), fld.fold_expr(e))
390390
}
391391
TyKind::Typeof(expr) => {
392392
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> {
10921092
PatKind::Range(e1, e2) => {
10931093
PatKind::Range(folder.fold_expr(e1), folder.fold_expr(e2))
10941094
},
1095-
PatKind::Vec(before, slice, after) => {
1096-
PatKind::Vec(before.move_map(|x| folder.fold_pat(x)),
1095+
PatKind::Slice(before, slice, after) => {
1096+
PatKind::Slice(before.move_map(|x| folder.fold_pat(x)),
10971097
slice.map(|x| folder.fold_pat(x)),
10981098
after.move_map(|x| folder.fold_pat(x)))
10991099
}

src/libsyntax/parse/parser.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1386,8 +1386,8 @@ impl<'a> Parser<'a> {
13861386
// Parse the `; e` in `[ i32; e ]`
13871387
// where `e` is a const expression
13881388
let t = match self.maybe_parse_fixed_length_of_vec()? {
1389-
None => TyKind::Vec(t),
1390-
Some(suffix) => TyKind::FixedLengthVec(t, suffix)
1389+
None => TyKind::Slice(t),
1390+
Some(suffix) => TyKind::Array(t, suffix)
13911391
};
13921392
self.expect(&token::CloseDelim(token::Bracket))?;
13931393
t
@@ -3587,7 +3587,7 @@ impl<'a> Parser<'a> {
35873587
self.bump();
35883588
let (before, slice, after) = self.parse_pat_vec_elements()?;
35893589
self.expect(&token::CloseDelim(token::Bracket))?;
3590-
pat = PatKind::Vec(before, slice, after);
3590+
pat = PatKind::Slice(before, slice, after);
35913591
}
35923592
// At this point, token != _, &, &&, (, [
35933593
_ => if self.eat_keyword(keywords::Mut) {

src/libsyntax/print/pprust.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ impl<'a> State<'a> {
972972
try!(self.maybe_print_comment(ty.span.lo));
973973
try!(self.ibox(0));
974974
match ty.node {
975-
ast::TyKind::Vec(ref ty) => {
975+
ast::TyKind::Slice(ref ty) => {
976976
try!(word(&mut self.s, "["));
977977
try!(self.print_type(&ty));
978978
try!(word(&mut self.s, "]"));
@@ -1039,7 +1039,7 @@ impl<'a> State<'a> {
10391039
ast::TyKind::ImplTrait(ref bounds) => {
10401040
try!(self.print_bounds("impl ", &bounds[..]));
10411041
}
1042-
ast::TyKind::FixedLengthVec(ref ty, ref v) => {
1042+
ast::TyKind::Array(ref ty, ref v) => {
10431043
try!(word(&mut self.s, "["));
10441044
try!(self.print_type(&ty));
10451045
try!(word(&mut self.s, "; "));
@@ -2573,7 +2573,7 @@ impl<'a> State<'a> {
25732573
try!(word(&mut self.s, "..."));
25742574
try!(self.print_expr(&end));
25752575
}
2576-
PatKind::Vec(ref before, ref slice, ref after) => {
2576+
PatKind::Slice(ref before, ref slice, ref after) => {
25772577
try!(word(&mut self.s, "["));
25782578
try!(self.commasep(Inconsistent,
25792579
&before[..],

src/libsyntax/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ fn mk_tests(cx: &TestCtxt) -> P<ast::Item> {
564564
let static_lt = ecx.lifetime(sp, keywords::StaticLifetime.name());
565565
// &'static [self::test::TestDescAndFn]
566566
let static_type = ecx.ty_rptr(sp,
567-
ecx.ty(sp, ast::TyKind::Vec(struct_type)),
567+
ecx.ty(sp, ast::TyKind::Slice(struct_type)),
568568
Some(static_lt),
569569
ast::Mutability::Immutable);
570570
// static TESTS: $static_type = &[...];

src/libsyntax/visit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ pub fn walk_variant<V>(visitor: &mut V, variant: &Variant, generics: &Generics,
313313

314314
pub fn walk_ty<V: Visitor>(visitor: &mut V, typ: &Ty) {
315315
match typ.node {
316-
TyKind::Vec(ref ty) | TyKind::Paren(ref ty) => {
316+
TyKind::Slice(ref ty) | TyKind::Paren(ref ty) => {
317317
visitor.visit_ty(ty)
318318
}
319319
TyKind::Ptr(ref mutable_type) => {
@@ -341,7 +341,7 @@ pub fn walk_ty<V: Visitor>(visitor: &mut V, typ: &Ty) {
341341
visitor.visit_ty(ty);
342342
walk_list!(visitor, visit_ty_param_bound, bounds);
343343
}
344-
TyKind::FixedLengthVec(ref ty, ref expression) => {
344+
TyKind::Array(ref ty, ref expression) => {
345345
visitor.visit_ty(ty);
346346
visitor.visit_expr(expression)
347347
}
@@ -434,7 +434,7 @@ pub fn walk_pat<V: Visitor>(visitor: &mut V, pattern: &Pat) {
434434
visitor.visit_expr(upper_bound)
435435
}
436436
PatKind::Wild => (),
437-
PatKind::Vec(ref prepatterns, ref slice_pattern, ref postpatterns) => {
437+
PatKind::Slice(ref prepatterns, ref slice_pattern, ref postpatterns) => {
438438
walk_list!(visitor, visit_pat, prepatterns);
439439
walk_list!(visitor, visit_pat, slice_pattern);
440440
walk_list!(visitor, visit_pat, postpatterns);

src/libsyntax_ext/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ impl<'a, 'b> Context<'a, 'b> {
506506
-> P<ast::Expr> {
507507
let sp = piece_ty.span;
508508
let ty = ecx.ty_rptr(sp,
509-
ecx.ty(sp, ast::TyKind::Vec(piece_ty)),
509+
ecx.ty(sp, ast::TyKind::Slice(piece_ty)),
510510
Some(ecx.lifetime(sp, keywords::StaticLifetime.name())),
511511
ast::Mutability::Immutable);
512512
let slice = ecx.expr_vec_slice(sp, pieces);

0 commit comments

Comments
 (0)