1 //! Logic for validating block expressions i.e. `ast::BlockExpr`.
2
3 use crate::{
4 ast::{self, AstNode, HasAttrs},
5 SyntaxError,
6 SyntaxKind::*,
7 };
8
validate_block_expr(block: ast::BlockExpr, errors: &mut Vec<SyntaxError>)9 pub(crate) fn validate_block_expr(block: ast::BlockExpr, errors: &mut Vec<SyntaxError>) {
10 if let Some(parent) = block.syntax().parent() {
11 match parent.kind() {
12 FN | EXPR_STMT | STMT_LIST => return,
13 _ => {}
14 }
15 }
16 if let Some(stmt_list) = block.stmt_list() {
17 errors.extend(stmt_list.attrs().filter(|attr| attr.kind().is_inner()).map(|attr| {
18 SyntaxError::new(
19 "A block in this position cannot accept inner attributes",
20 attr.syntax().text_range(),
21 )
22 }));
23 }
24 }
25