diff options
| author | Stuart Pernsteiner <spernsteiner@galois.com> | 2017-09-07 10:28:31 -0400 |
|---|---|---|
| committer | Stuart Pernsteiner <spernsteiner@galois.com> | 2017-09-07 10:28:31 -0400 |
| commit | 3454d99cb6355ab60c95e72d96e04eb9c69a6138 (patch) | |
| tree | a167db52e3405e84dd056a17d37d228f5739a451 /src/libsyntax/util | |
| parent | 347db068a5786d3cac6e2204d7e14b635ece558d (diff) | |
| download | rust-3454d99cb6355ab60c95e72d96e04eb9c69a6138.tar.gz rust-3454d99cb6355ab60c95e72d96e04eb9c69a6138.zip | |
pprust: increase precedence of block-like exprs
Diffstat (limited to 'src/libsyntax/util')
| -rw-r--r-- | src/libsyntax/util/parser.rs | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/libsyntax/util/parser.rs b/src/libsyntax/util/parser.rs index af42b4be694..a4f06cb1b45 100644 --- a/src/libsyntax/util/parser.rs +++ b/src/libsyntax/util/parser.rs @@ -219,7 +219,6 @@ impl AssocOp { pub const PREC_RESET: i8 = -100; pub const PREC_CLOSURE: i8 = -40; pub const PREC_JUMP: i8 = -30; -pub const PREC_BLOCK: i8 = -20; pub const PREC_RANGE: i8 = -10; // The range 2 ... 14 is reserved for AssocOp binary operator precedences. pub const PREC_PREFIX: i8 = 50; @@ -236,16 +235,6 @@ pub fn expr_precedence(expr: &ast::Expr) -> i8 { ExprKind::Ret(..) | ExprKind::Yield(..) => PREC_JUMP, - ExprKind::If(..) | - ExprKind::IfLet(..) | - ExprKind::While(..) | - ExprKind::WhileLet(..) | - ExprKind::ForLoop(..) | - ExprKind::Loop(..) | - ExprKind::Match(..) | - ExprKind::Block(..) | - ExprKind::Catch(..) => PREC_BLOCK, - // `Range` claims to have higher precedence than `Assign`, but `x .. x = x` fails to parse, // instead of parsing as `(x .. x) = x`. Giving `Range` a lower precedence ensures that // `pprust` will add parentheses in the right places to get the desired parse. @@ -284,6 +273,15 @@ pub fn expr_precedence(expr: &ast::Expr) -> i8 { ExprKind::Lit(..) | ExprKind::Path(..) | ExprKind::Paren(..) | + ExprKind::If(..) | + ExprKind::IfLet(..) | + ExprKind::While(..) | + ExprKind::WhileLet(..) | + ExprKind::ForLoop(..) | + ExprKind::Loop(..) | + ExprKind::Match(..) | + ExprKind::Block(..) | + ExprKind::Catch(..) | ExprKind::Struct(..) => PREC_PAREN, } } |
