diff options
Diffstat (limited to 'crates/ra_syntax/src/validation')
-rw-r--r-- | crates/ra_syntax/src/validation/block.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/validation/block.rs b/crates/ra_syntax/src/validation/block.rs new file mode 100644 index 000000000..9e1949124 --- /dev/null +++ b/crates/ra_syntax/src/validation/block.rs | |||
@@ -0,0 +1,24 @@ | |||
1 | use crate::{SyntaxKind::*, | ||
2 | ast::{self, AttrsOwner, AstNode}, | ||
3 | yellow::{ | ||
4 | SyntaxError, | ||
5 | SyntaxErrorKind::*, | ||
6 | }, | ||
7 | }; | ||
8 | |||
9 | pub(crate) fn validate_block_node(node: &ast::Block, errors: &mut Vec<SyntaxError>) { | ||
10 | if let Some(parent) = node.syntax().parent() { | ||
11 | match parent.kind() { | ||
12 | FN_DEF => return, | ||
13 | BLOCK_EXPR => match parent.parent().map(|v| v.kind()) { | ||
14 | Some(EXPR_STMT) | Some(BLOCK) => return, | ||
15 | _ => {} | ||
16 | }, | ||
17 | _ => {} | ||
18 | } | ||
19 | } | ||
20 | errors.extend( | ||
21 | node.attrs() | ||
22 | .map(|attr| SyntaxError::new(InvalidBlockAttr, attr.syntax().range())), | ||
23 | ) | ||
24 | } | ||