syntax/validation/
block.rs

1//! Logic for validating block expressions i.e. `ast::BlockExpr`.
2
3use crate::{
4    SyntaxError,
5    SyntaxKind::*,
6    ast::{self, AstNode, HasAttrs},
7};
8
9pub(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 | MACRO_STMTS => 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}