Rollup merge of #78376 - Aaron1011:feature/consistent-empty-expr, r=petrochenkov
Treat trailing semicolon as a statement in macro call See #61733 (comment) We now preserve the trailing semicolon in a macro invocation, even if the macro expands to nothing. As a result, the following code no longer compiles: ```rust macro_rules! empty { () => { } } fn foo() -> bool { //~ ERROR mismatched { true } //~ ERROR mismatched empty!(); } ``` Previously, `{ true }` would be considered the trailing expression, even though there's a semicolon in `empty!();` This makes macro expansion more token-based.
This commit is contained in:
commit
0716724a0b
6 changed files with 77 additions and 2 deletions
|
@ -905,6 +905,13 @@ pub struct Stmt {
|
|||
}
|
||||
|
||||
impl Stmt {
|
||||
pub fn has_trailing_semicolon(&self) -> bool {
|
||||
match &self.kind {
|
||||
StmtKind::Semi(_) => true,
|
||||
StmtKind::MacCall(mac) => matches!(mac.style, MacStmtStyle::Semicolon),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
pub fn add_trailing_semicolon(mut self) -> Self {
|
||||
self.kind = match self.kind {
|
||||
StmtKind::Expr(expr) => StmtKind::Semi(expr),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue