always wrap block into an expression

This commit is contained in:
Aleksey Kladov 2019-09-02 19:33:02 +03:00
parent a8397deab9
commit 3c2dea7f55
5 changed files with 19 additions and 14 deletions

View file

@ -5,18 +5,18 @@ use crate::{
SyntaxKind::*,
};
pub(crate) fn validate_block_node(node: ast::Block, errors: &mut Vec<SyntaxError>) {
if let Some(parent) = node.syntax().parent() {
pub(crate) fn validate_block_expr(expr: ast::BlockExpr, errors: &mut Vec<SyntaxError>) {
if let Some(parent) = expr.syntax().parent() {
match parent.kind() {
FN_DEF => return,
BLOCK_EXPR => match parent.parent().map(|v| v.kind()) {
Some(EXPR_STMT) | Some(BLOCK) => return,
_ => {}
},
FN_DEF | EXPR_STMT | BLOCK => return,
_ => {}
}
}
errors.extend(
node.attrs().map(|attr| SyntaxError::new(InvalidBlockAttr, attr.syntax().text_range())),
)
if let Some(block) = expr.block() {
errors.extend(
block
.attrs()
.map(|attr| SyntaxError::new(InvalidBlockAttr, attr.syntax().text_range())),
)
}
}