diff options
| author | bors <bors@rust-lang.org> | 2016-03-08 01:31:04 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-03-08 01:31:04 -0800 |
| commit | 3af60f831f75ae2632bbfd4c1aa66049ec2d486a (patch) | |
| tree | 211677e1c9a46740ec3fc9cba30c5f7346ad675d /src/libsyntax/parse | |
| parent | a9ffe67f98366c58f13e89851d025e8e063f0bb2 (diff) | |
| parent | 2de4932453a99a19e9033edb47db7a66a612188c (diff) | |
| download | rust-3af60f831f75ae2632bbfd4c1aa66049ec2d486a.tar.gz rust-3af60f831f75ae2632bbfd4c1aa66049ec2d486a.zip | |
Auto merge of #31954 - japaric:rfc243, r=nikomatsakis
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
---
cc @aturon @eddyb
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d9714cc1e25..53b53415429 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2534,6 +2534,12 @@ impl<'a> Parser<'a> { let mut e = e0; let mut hi; loop { + // expr? + while self.eat(&token::Question) { + let hi = self.span.hi; + e = self.mk_expr(lo, hi, ExprKind::Try(e), None); + } + // expr.f if self.eat(&token::Dot) { match self.token { @@ -2907,7 +2913,6 @@ impl<'a> Parser<'a> { } }; - if self.expr_is_complete(&lhs) { // Semi-statement forms are odd. See https://github.com/rust-lang/rust/issues/29071 return Ok(lhs); |
