mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Parse and validate attributes in blocks
This commit is contained in:
parent
137b1ccb71
commit
00e6b5d26c
10 changed files with 352 additions and 0 deletions
24
crates/ra_syntax/src/validation/block.rs
Normal file
24
crates/ra_syntax/src/validation/block.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use crate::{SyntaxKind::*,
|
||||
ast::{self, AttrsOwner, AstNode},
|
||||
yellow::{
|
||||
SyntaxError,
|
||||
SyntaxErrorKind::*,
|
||||
},
|
||||
};
|
||||
|
||||
pub(crate) fn validate_block_node(node: &ast::Block, errors: &mut Vec<SyntaxError>) {
|
||||
if let Some(parent) = node.syntax().parent() {
|
||||
match parent.kind() {
|
||||
FN_DEF => return,
|
||||
BLOCK_EXPR => match parent.parent().map(|v| v.kind()) {
|
||||
Some(EXPR_STMT) | Some(BLOCK) => return,
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
errors.extend(
|
||||
node.attrs()
|
||||
.map(|attr| SyntaxError::new(InvalidBlockAttr, attr.syntax().range())),
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue