From bf274bc18bcbfea1377c5c64ae0cc099b03d9beb Mon Sep 17 00:00:00 2001 From: P1start Date: Sun, 10 Aug 2014 15:54:33 +1200 Subject: 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); --- src/libsyntax/print/pprust.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/libsyntax/print') 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)) -- cgit 1.4.1-3-g733a5