aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/validation/block.rs
blob: c5588658d8877f5e36d0ed82e56c188543ea34c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use crate::{
    ast::{self, AstNode, AttrsOwner},
    SyntaxError,
    SyntaxErrorKind::*,
    SyntaxKind::*,
};

pub(crate) fn validate_block_node(node: ast::Block, errors: &mut Vec<SyntaxError>) {
    if let Some(parent) = node.syntax().parent() {
        match parent.kind() {
            FN_DEF => return,
            BLOCK_EXPR => match parent.parent().map(|v| v.kind()) {
                Some(EXPR_STMT) | Some(BLOCK) => return,
                _ => {}
            },
            _ => {}
        }
    }
    errors.extend(
        node.attrs().map(|attr| SyntaxError::new(InvalidBlockAttr, attr.syntax().text_range())),
    )
}