2020-02-06 02:33:18 +02:00
|
|
|
//! Logic for validating block expressions i.e. `ast::BlockExpr`.
|
2019-09-30 11:58:53 +03:00
|
|
|
|
2019-07-04 23:05:17 +03:00
|
|
|
use crate::{
|
|
|
|
ast::{self, AstNode, AttrsOwner},
|
2019-02-20 16:16:14 +03:00
|
|
|
SyntaxError,
|
2019-07-04 23:05:17 +03:00
|
|
|
SyntaxKind::*,
|
2019-01-28 20:03:56 +00:00
|
|
|
};
|
|
|
|
|
2020-05-02 01:18:19 +02:00
|
|
|
pub(crate) fn validate_block_expr(block: ast::BlockExpr, errors: &mut Vec<SyntaxError>) {
|
|
|
|
if let Some(parent) = block.syntax().parent() {
|
2019-01-28 20:03:56 +00:00
|
|
|
match parent.kind() {
|
2020-07-30 14:51:08 +02:00
|
|
|
FN | EXPR_STMT | BLOCK_EXPR => return,
|
2019-01-28 20:03:56 +00:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 01:18:19 +02:00
|
|
|
errors.extend(block.attrs().map(|attr| {
|
|
|
|
SyntaxError::new(
|
|
|
|
"A block in this position cannot accept inner attributes",
|
|
|
|
attr.syntax().text_range(),
|
|
|
|
)
|
|
|
|
}))
|
2019-01-28 20:03:56 +00:00
|
|
|
}
|