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

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

Open
topecongiro opened this issue Aug 18, 2019 · 2 comments
Open
Labels
A-parser Area: The parsing of Rust source code to an AST. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@topecongiro
Copy link
Contributor

topecongiro commented Aug 18, 2019

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.

@jonas-schievink jonas-schievink added A-parser Area: The parsing of Rust source code to an AST. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 18, 2019
@varkor
Copy link
Member

varkor commented Aug 18, 2019

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.

@GrigorenkoPV
Copy link
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
Labels
A-parser Area: The parsing of Rust source code to an AST. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants