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

@ -342,14 +342,7 @@ fn inner_attributes(
ast::Impl(it) => it.assoc_item_list()?.syntax().clone(),
ast::Module(it) => it.item_list()?.syntax().clone(),
ast::BlockExpr(it) => {
use syntax::SyntaxKind::{BLOCK_EXPR , EXPR_STMT};
// 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.
let may_carry_attributes = matches!(
it.syntax().parent().map(|it| it.kind()),
Some(BLOCK_EXPR | EXPR_STMT)
);
if !may_carry_attributes {
if !it.may_carry_attributes() {
return None
}
syntax.clone()