Auto merge of #30375 - aaronkeen:issue_28777, r=eddyb
RESTRICTION_STMT_EXPR restriction to allow subsequent expressions to contain braces. https://github.com/rust-lang/rust/issues/28777
This commit is contained in:
@@ -2809,16 +2809,25 @@ impl<'a> Parser<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let rhs = try!(match op.fixity() {
|
let rhs = try!(match op.fixity() {
|
||||||
Fixity::Right => self.with_res(restrictions, |this|{
|
Fixity::Right => self.with_res(
|
||||||
this.parse_assoc_expr_with(op.precedence(), LhsExpr::NotYetParsed)
|
restrictions - Restrictions::RESTRICTION_STMT_EXPR,
|
||||||
|
|this| {
|
||||||
|
this.parse_assoc_expr_with(op.precedence(),
|
||||||
|
LhsExpr::NotYetParsed)
|
||||||
}),
|
}),
|
||||||
Fixity::Left => self.with_res(restrictions, |this|{
|
Fixity::Left => self.with_res(
|
||||||
this.parse_assoc_expr_with(op.precedence() + 1, LhsExpr::NotYetParsed)
|
restrictions - Restrictions::RESTRICTION_STMT_EXPR,
|
||||||
|
|this| {
|
||||||
|
this.parse_assoc_expr_with(op.precedence() + 1,
|
||||||
|
LhsExpr::NotYetParsed)
|
||||||
}),
|
}),
|
||||||
// We currently have no non-associative operators that are not handled above by
|
// We currently have no non-associative operators that are not handled above by
|
||||||
// the special cases. The code is here only for future convenience.
|
// the special cases. The code is here only for future convenience.
|
||||||
Fixity::None => self.with_res(restrictions, |this|{
|
Fixity::None => self.with_res(
|
||||||
this.parse_assoc_expr_with(op.precedence() + 1, LhsExpr::NotYetParsed)
|
restrictions - Restrictions::RESTRICTION_STMT_EXPR,
|
||||||
|
|this| {
|
||||||
|
this.parse_assoc_expr_with(op.precedence() + 1,
|
||||||
|
LhsExpr::NotYetParsed)
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,14 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// compile-flags: -Z parse-only
|
fn that_odd_parse(c: bool, n: usize) -> u32 {
|
||||||
|
let x = 2;
|
||||||
fn that_odd_parse() {
|
let a = [1, 2, 3, 4];
|
||||||
// see assoc-oddities-1 for explanation
|
let b = [5, 6, 7, 7];
|
||||||
x + if c { a } else { b }[n]; //~ ERROR expected one of
|
x + if c { a } else { b }[n]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
assert_eq!(4, that_odd_parse(true, 1));
|
||||||
|
assert_eq!(8, that_odd_parse(false, 1));
|
||||||
}
|
}
|
||||||
30
src/test/run-pass/issue-28777.rs
Normal file
30
src/test/run-pass/issue-28777.rs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let v1 = { 1 + {2} * {3} };
|
||||||
|
let v2 = 1 + {2} * {3} ;
|
||||||
|
|
||||||
|
assert_eq!(7, v1);
|
||||||
|
assert_eq!(7, v2);
|
||||||
|
|
||||||
|
let v3;
|
||||||
|
v3 = { 1 + {2} * {3} };
|
||||||
|
let v4;
|
||||||
|
v4 = 1 + {2} * {3};
|
||||||
|
assert_eq!(7, v3);
|
||||||
|
assert_eq!(7, v4);
|
||||||
|
|
||||||
|
let v5 = { 1 + {2} * 3 };
|
||||||
|
assert_eq!(7, v5);
|
||||||
|
|
||||||
|
let v9 = { 1 + if 1 > 2 {1} else {2} * {3} };
|
||||||
|
assert_eq!(7, v9);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user