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::{
|
|
|
|
ast::{self, AstNode, AttrsOwner},
|
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
|
|
|
};
|
|
|
|
|
2019-09-02 16:33:02 +00:00
|
|
|
pub(crate) fn validate_block_expr(expr: ast::BlockExpr, errors: &mut Vec<SyntaxError>) {
|
|
|
|
if let Some(parent) = expr.syntax().parent() {
|
2019-01-28 20:03:56 +00:00
|
|
|
match parent.kind() {
|
2019-09-02 16:33:02 +00:00
|
|
|
FN_DEF | EXPR_STMT | BLOCK => return,
|
2019-01-28 20:03:56 +00:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
2019-09-02 16:33:02 +00:00
|
|
|
if let Some(block) = expr.block() {
|
2020-02-06 00:33:18 +00:00
|
|
|
errors.extend(block.attrs().map(|attr| {
|
|
|
|
SyntaxError::new(
|
|
|
|
"A block in this position cannot accept inner attributes",
|
|
|
|
attr.syntax().text_range(),
|
|
|
|
)
|
|
|
|
}))
|
2019-09-02 16:33:02 +00:00
|
|
|
}
|
2019-01-28 20:03:56 +00:00
|
|
|
}
|