diff options
author | Igor Aleksanov <[email protected]> | 2020-08-14 05:34:07 +0100 |
---|---|---|
committer | Igor Aleksanov <[email protected]> | 2020-08-14 05:34:07 +0100 |
commit | c26c911ec1e6c2ad1dcb7d155a6a1d528839ad1a (patch) | |
tree | 7cff36c38234be0afb65273146d8247083a5cfeb /crates/syntax/src/validation | |
parent | 3c018bf84de5c693b5ee1c6bec0fed3b201c2060 (diff) | |
parent | f1f73649a686dc6e6449afc35e0fa6fed00e225d (diff) |
Merge branch 'master' into add-disable-diagnostics
Diffstat (limited to 'crates/syntax/src/validation')
-rw-r--r-- | crates/syntax/src/validation/block.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/crates/syntax/src/validation/block.rs b/crates/syntax/src/validation/block.rs new file mode 100644 index 000000000..ad9901468 --- /dev/null +++ b/crates/syntax/src/validation/block.rs | |||
@@ -0,0 +1,22 @@ | |||
1 | //! Logic for validating block expressions i.e. `ast::BlockExpr`. | ||
2 | |||
3 | use crate::{ | ||
4 | ast::{self, AstNode, AttrsOwner}, | ||
5 | SyntaxError, | ||
6 | SyntaxKind::*, | ||
7 | }; | ||
8 | |||
9 | pub(crate) fn validate_block_expr(block: ast::BlockExpr, errors: &mut Vec<SyntaxError>) { | ||
10 | if let Some(parent) = block.syntax().parent() { | ||
11 | match parent.kind() { | ||
12 | FN | EXPR_STMT | BLOCK_EXPR => return, | ||
13 | _ => {} | ||
14 | } | ||
15 | } | ||
16 | errors.extend(block.attrs().map(|attr| { | ||
17 | SyntaxError::new( | ||
18 | "A block in this position cannot accept inner attributes", | ||
19 | attr.syntax().text_range(), | ||
20 | ) | ||
21 | })) | ||
22 | } | ||