Skip to content

Redundant semicolons are parsed as an empty tuple semicolon statement #63679

Closed

Description

@topecongiro
fn foo() {
    let _ = 3;;;;
}

Given the above example, the rustc parser used to silently drop the redundant semicolons (;;;) from the AST. However, recently the parse has changed how it treats the redundant semicolons - they are now parsed as a semicolon statement with an empty tuple:

Stmt {
    node: StmtKind::Semi(Expr {
        node: ExprKind::Tup(vec![]),
        ..
    }),
    ..
}

Found this while updating rustc-ap-syntax to 562.0.0 (which is built from the commit fc8765d) in rustfmt.

Activity

  1. added
    A-parserArea: The lexing & parsing of Rust source code to an AST
    C-bugCategory: This is a bug.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Aug 18, 2019
  2. varkor commented on Aug 18, 2019

    @varkor
    Contributor

    Ah, this is due to #62984, where we need to record the redundant semicolons for the lint. Sorry, I forgot that this would affect non-rustc parsing. We should change the representation, but I'm not sure what would be ideal. Perhaps storing the number of semicolons in StmtKind::Semi.

  3. GrigorenkoPV commented on Sep 22, 2024

    @GrigorenkoPV
    Contributor

    This should probably be closed.

    REDUNDANT_SEMICOLONS is now an internal lint, which seems to be using StmtKind::Empty instead of tuples. Also rustfmt automatically removes any redundant semicolons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions