Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit proper errors when on missing closure braces #88546

Merged
merged 1 commit into from
Sep 11, 2021

Commits on Sep 9, 2021

  1. Emit proper errors on missing closure braces

    This commit focuses on emitting clean errors for the following syntax
    error:
    
    ```
    Some(42).map(|a|
        dbg!(a);
        a
    );
    ```
    
    Previous implementation tried to recover after parsing the closure body
    (the `dbg` expression) by replacing the next `;` with a `,`, which made
    the next expression belong to the next function argument. As such, the
    following errors were emitted (among others):
      - the semicolon token was not expected,
      - a is not in scope,
      - Option::map is supposed to take one argument, not two.
    
    This commit allows us to gracefully handle this situation by adding
    giving the parser the ability to remember when it has just parsed a
    closure body inside a function call. When this happens, we can treat the
    unexpected `;` specifically and try to parse as much statements as
    possible in order to eat the whole block. When we can't parse statements
    anymore, we generate a clean error indicating that the braces are
    missing, and return an ExprKind::Err.
    Sasha Pourcelot committed Sep 9, 2021
    Configuration menu
    Copy the full SHA
    b21425d View commit details
    Browse the repository at this point in the history