about summary refs log tree commit diff
path: root/src/libsyntax/print
diff options
context:
space:
mode:
authorP1start <rewi-github@whanau.org>2014-08-10 15:54:33 +1200
committerP1start <rewi-github@whanau.org>2014-09-10 10:25:12 +1200
commitbf274bc18bcbfea1377c5c64ae0cc099b03d9beb (patch)
tree78f4b0455b6c93991836bed81b7b57096737b462 /src/libsyntax/print
parent651106462c357b71a4ca2c02ba2bfedfc38b0035 (diff)
downloadrust-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/print')
-rw-r--r--src/libsyntax/print/pprust.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index eaeb6aaab8a..a4dff45ad35 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -1607,6 +1607,18 @@ impl<'a> State<'a> {
                     try!(word(&mut self.s, ">"));
                 }
             }
+            ast::ExprTupField(ref expr, id, ref tys) => {
+                try!(self.print_expr(&**expr));
+                try!(word(&mut self.s, "."));
+                try!(self.print_uint(id.node));
+                if tys.len() > 0u {
+                    try!(word(&mut self.s, "::<"));
+                    try!(self.commasep(
+                        Inconsistent, tys.as_slice(),
+                        |s, ty| s.print_type_ref(ty)));
+                    try!(word(&mut self.s, ">"));
+                }
+            }
             ast::ExprIndex(ref expr, ref index) => {
                 try!(self.print_expr(&**expr));
                 try!(word(&mut self.s, "["));
@@ -1738,6 +1750,10 @@ impl<'a> State<'a> {
         self.ann.post(self, NodeIdent(&ident))
     }
 
+    pub fn print_uint(&mut self, i: uint) -> IoResult<()> {
+        word(&mut self.s, i.to_string().as_slice())
+    }
+
     pub fn print_name(&mut self, name: ast::Name) -> IoResult<()> {
         try!(word(&mut self.s, token::get_name(name).get()));
         self.ann.post(self, NodeName(&name))