]> git.lizzy.rs Git - rust.git/commit
Merge #996
authorbors[bot] <bors[bot]@users.noreply.github.com>
Tue, 19 Mar 2019 10:36:17 +0000 (10:36 +0000)
committerbors[bot] <bors[bot]@users.noreply.github.com>
Tue, 19 Mar 2019 10:36:17 +0000 (10:36 +0000)
commit5b6ad0971c050981deb10c56ad2634293f104228
tree7f76ce1da6ed9e245f5b4ef14257418c66f59577
parent91576afc7e64f11dde2bed14b578e4914d253a6a
parent4cf179c089aeed381cd67bcd265e76a27f11facd
Merge #996

996: Allow attributes on top level expressions r=matklad a=pcpthm

This PR modifies parser to allow outer attributes on top level expression. Here, top level expression means either
- Expression statement e.g. `foo();`
- Last expression in a block without semicolon `bar()` in `{ foo(); bar() }`.

Except for binary operation expressions and `if` expressions, which are errors (feature gated) in rustc.
Attributes on inner expressions like `foo(#[a] 1)` are not implemented.

I first tried to implement this by passing `Maker` to expression parsers. However, this implementation couldn't parse `#[attr] foo()` correctly as `CallExpr(Attr(..), PathExpr(..), ArgList(..))` and instead parsed incorrectly as `CallExpr(PathExpr(Attr(..), ..), ArgList(..))` due to the way left recursion is handled.
In the end, I introduce `undo_completion` method. Which is not the suggested approach, but it seems not very bad.

Fix #759.

Co-authored-by: pcpthm <pcpthm@gmail.com>