Derive block attributes from block item tree

This commit is contained in:
Lukas Wirth 2023-08-10 18:52:27 +02:00
parent 05b0612051
commit e5b23e3bc1
8 changed files with 41 additions and 27 deletions

View file

@ -61,6 +61,14 @@ impl ast::BlockExpr {
pub fn tail_expr(&self) -> Option<ast::Expr> {
self.stmt_list()?.tail_expr()
}
/// Block expressions accept outer and inner attributes, but only when they are the outer
/// expression of an expression statement or the final expression of another block expression.
pub fn may_carry_attributes(&self) -> bool {
matches!(
self.syntax().parent().map(|it| it.kind()),
Some(SyntaxKind::BLOCK_EXPR | SyntaxKind::EXPR_STMT)
)
}
}
#[derive(Debug, PartialEq, Eq, Clone)]