diff options
| author | P1start <rewi-github@whanau.org> | 2014-08-10 15:54:33 +1200 |
|---|---|---|
| committer | P1start <rewi-github@whanau.org> | 2014-09-10 10:25:12 +1200 |
| commit | bf274bc18bcbfea1377c5c64ae0cc099b03d9beb (patch) | |
| tree | 78f4b0455b6c93991836bed81b7b57096737b462 /src/libsyntax/fold.rs | |
| parent | 651106462c357b71a4ca2c02ba2bfedfc38b0035 (diff) | |
| download | rust-bf274bc18bcbfea1377c5c64ae0cc099b03d9beb.tar.gz rust-bf274bc18bcbfea1377c5c64ae0cc099b03d9beb.zip | |
Implement tuple and tuple struct indexing
This allows code to access the fields of tuples and tuple structs:
let x = (1i, 2i);
assert_eq!(x.1, 2);
struct Point(int, int);
let origin = Point(0, 0);
assert_eq!(origin.0, 0);
assert_eq!(origin.1, 0);
Diffstat (limited to 'src/libsyntax/fold.rs')
| -rw-r--r-- | src/libsyntax/fold.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 7deabed04b8..30b7317fa56 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -134,6 +134,10 @@ pub trait Folder { noop_fold_ident(i, self) } + fn fold_uint(&mut self, i: uint) -> uint { + noop_fold_uint(i, self) + } + fn fold_path(&mut self, p: &Path) -> Path { noop_fold_path(p, self) } @@ -466,6 +470,10 @@ pub fn noop_fold_ident<T: Folder>(i: Ident, _: &mut T) -> Ident { i } +pub fn noop_fold_uint<T: Folder>(i: uint, _: &mut T) -> uint { + i +} + pub fn noop_fold_path<T: Folder>(p: &Path, fld: &mut T) -> Path { ast::Path { span: fld.new_span(p.span), @@ -1180,6 +1188,11 @@ pub fn noop_fold_expr<T: Folder>(e: Gc<Expr>, folder: &mut T) -> Gc<Expr> { respan(id.span, folder.fold_ident(id.node)), tys.iter().map(|&x| folder.fold_ty(x)).collect()) } + ExprTupField(el, id, ref tys) => { + ExprTupField(folder.fold_expr(el), + respan(id.span, folder.fold_uint(id.node)), + tys.iter().map(|&x| folder.fold_ty(x)).collect()) + } ExprIndex(el, er) => { ExprIndex(folder.fold_expr(el), folder.fold_expr(er)) } |
