2020-02-06 00:33:18 +00:00
|
|
|
//! Logic for validating block expressions i.e. `ast::BlockExpr`.
|
2019-09-30 08:58:53 +00:00
|
|
|
|
2019-07-04 20:05:17 +00:00
|
|
|
use crate::{
|
2021-09-27 10:54:24 +00:00
|
|
|
ast::{self, AstNode, HasAttrs},
|
2019-02-20 13:16:14 +00:00
|
|
|
SyntaxError,
|
2019-07-04 20:05:17 +00:00
|
|
|
SyntaxKind::*,
|
2019-01-28 20:03:56 +00:00
|
|
|
};
|
|
|
|
|
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() {
|
2019-01-28 20:03:56 +00:00
|
|
|
match parent.kind() {
|
2021-09-26 09:12:57 +00:00
|
|
|
FN | EXPR_STMT | STMT_LIST => return,
|
2019-01-28 20:03:56 +00:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
2021-09-26 09:12:57 +00:00
|
|
|
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(),
|
|
|
|
)
|
2021-10-03 12:39:43 +00:00
|
|
|
}));
|
2021-09-26 09:12:57 +00:00
|
|
|
}
|
2019-01-28 20:03:56 +00:00
|
|
|
}
|