From 210dd611aa1bd80ed2f4e663b3c4b87b3cea069a Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 28 Feb 2016 17:38:48 -0500 Subject: implement the `?` operator The `?` postfix operator is sugar equivalent to the try! macro, but is more amenable to chaining: `File::open("foo")?.metadata()?.is_dir()`. `?` is accepted on any *expression* that can return a `Result`, e.g. `x()?`, `y!()?`, `{z}?`, `(w)?`, etc. And binds more tightly than unary operators, e.g. `!x?` is parsed as `!(x?)`. cc #31436 --- src/libsyntax/print/pprust.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/libsyntax/print') diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 55c1af44cab..2cfed1f82f7 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2277,6 +2277,10 @@ impl<'a> State<'a> { try!(self.print_inner_attributes_inline(attrs)); try!(self.print_expr(&e)); try!(self.pclose()); + }, + ast::ExprKind::Try(ref e) => { + try!(self.print_expr(e)); + try!(word(&mut self.s, "?")) } } try!(self.ann.post(self, NodeExpr(expr))); -- cgit 1.4.1-3-g733a5