rust/crates/syntax/src/validation/block.rs
Aramis Razzaghipour 55c0b86cde
Add semicolons for consistency
`clippy::semicolon_if_nothing_returned`
2021-10-03 23:39:43 +11:00

25 lines
738 B
Rust

//! Logic for validating block expressions i.e. `ast::BlockExpr`.
use crate::{
ast::{self, AstNode, HasAttrs},
SyntaxError,
SyntaxKind::*,
};
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(),
)
}));
}
}