Only eat semicolons for statements that need them

When parsing a statement (e.g. inside a function body),
we now consider `struct Foo {};` and `$stmt;` to each consist
of two statements: `struct Foo {}` and `;`, and `$stmt` and `;`.

As a result, an attribute macro invoke as
`fn foo() { #[attr] struct Bar{}; }` will see `struct Bar{}` as its
input. Additionally, the 'unused semicolon' lint now fires in more
places.
This commit is contained in:
Aaron Hill 2020-11-25 16:52:24 -05:00
parent de88bf148b
commit 758834d3e2
No known key found for this signature in database
GPG Key ID: B4087E510E98B164
2 changed files with 2 additions and 8 deletions

View File

@ -473,8 +473,7 @@ pub fn parse_full_stmt(
// so capture it
add_semi_token(local.tokens.as_mut());
}
StmtKind::Empty => eat_semi = false,
_ => {}
StmtKind::Empty | StmtKind::Item(_) | StmtKind::Semi(_) => eat_semi = false,
}
if eat_semi && self.eat(&token::Semi) {

View File

@ -261,7 +261,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/allowed-attr-stmt-expr.rs:53:54: 53:56 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct Other { } ;
PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct Other { }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
@ -291,9 +291,4 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
stream: TokenStream [],
span: $DIR/allowed-attr-stmt-expr.rs:57:18: 57:20 (#0),
},
Punct {
ch: ';',
spacing: Alone,
span: $DIR/allowed-attr-stmt-expr.rs:57:20: 57:21 (#0),
},
]