rust-analyzer/crates/syntax/src/validation/block.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

25 lines
738 B
Rust
Raw Normal View History

//! Logic for validating block expressions i.e. `ast::BlockExpr`.
use crate::{
2021-09-27 10:54:24 +00:00
ast::{self, AstNode, HasAttrs},
2019-02-20 13:16:14 +00:00
SyntaxError,
SyntaxKind::*,
};
2020-05-01 23:18:19 +00:00
pub(crate) fn validate_block_expr(block: ast::BlockExpr, errors: &mut Vec<SyntaxError>) {
if let Some(parent) = block.syntax().parent() {
match parent.kind() {
FN | EXPR_STMT | STMT_LIST => return,
_ => {}
}
}
if let Some(stmt_list) = block.stmt_list() {
errors.extend(stmt_list.attrs().filter(|attr| attr.kind().is_inner()).map(|attr| {
SyntaxError::new(
"A block in this position cannot accept inner attributes",
attr.syntax().text_range(),
)
}));
}
}