]> git.lizzy.rs Git - rust.git/commitdiff
Merge #1951
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>
Tue, 8 Oct 2019 08:44:26 +0000 (08:44 +0000)
committerGitHub <noreply@github.com>
Tue, 8 Oct 2019 08:44:26 +0000 (08:44 +0000)
1951: Lower the precedence of the `as` operator. r=matklad a=goffrie

Previously, the `as` operator was being parsed like a postfix expression, and
therefore being given the highest possible precedence. That caused it to bind
more tightly than prefix operators, which it should not. Instead, parse it
somewhat like a normal binary expression with some special-casing.

Fixes #1851.

Co-authored-by: Geoffry Song <goffrie@gmail.com>
1  2 
crates/ra_parser/src/grammar/expressions.rs

index 74b23e2f7ccf41164f4f3560ff779f501563a729,c2a2060eb6345a39276af0a723ca684fa8431c04..45f2e3de47f0ec2637cdc381aa37454cf5a97b05
@@@ -335,15 -344,10 +344,16 @@@ fn lhs(p: &mut Parser, r: Restrictions
              // }
              //
              let (lhs, blocklike) = atom::atom_expr(p, r)?;
 -            return Some(postfix_expr(p, lhs, blocklike, !(r.prefer_stmt && blocklike.is_block())));
 +            return Some(postfix_expr(
 +                p,
 +                lhs,
 +                blocklike,
 +                !(r.prefer_stmt && blocklike.is_block()),
 +                r.forbid_structs,
 +            ));
          }
      };
+     // parse the interior of the unary expression
      expr_bp(p, r, 255);
      Some((m.complete(p, kind), BlockLike::NotBlock))
  }