From 3c2dea7f55830ba2391e5eb8525cdbb43ac666c2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 2 Sep 2019 19:33:02 +0300 Subject: always wrap block into an expression --- crates/ra_syntax/src/validation.rs | 2 +- crates/ra_syntax/src/validation/block.rs | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs index ee8797410..16824f3c4 100644 --- a/crates/ra_syntax/src/validation.rs +++ b/crates/ra_syntax/src/validation.rs @@ -97,7 +97,7 @@ pub(crate) fn validate(root: &SyntaxNode) -> Vec { for node in root.descendants() { let _ = visitor_ctx(&mut errors) .visit::(validate_literal) - .visit::(block::validate_block_node) + .visit::(block::validate_block_expr) .visit::(|it, errors| validate_numeric_name(it.name_ref(), errors)) .visit::(|it, errors| validate_numeric_name(it.name_ref(), errors)) .accept(&node); diff --git a/crates/ra_syntax/src/validation/block.rs b/crates/ra_syntax/src/validation/block.rs index c5588658d..3c9e96eb3 100644 --- a/crates/ra_syntax/src/validation/block.rs +++ b/crates/ra_syntax/src/validation/block.rs @@ -5,18 +5,18 @@ use crate::{ SyntaxKind::*, }; -pub(crate) fn validate_block_node(node: ast::Block, errors: &mut Vec) { - if let Some(parent) = node.syntax().parent() { +pub(crate) fn validate_block_expr(expr: ast::BlockExpr, errors: &mut Vec) { + if let Some(parent) = expr.syntax().parent() { match parent.kind() { - FN_DEF => return, - BLOCK_EXPR => match parent.parent().map(|v| v.kind()) { - Some(EXPR_STMT) | Some(BLOCK) => return, - _ => {} - }, + FN_DEF | EXPR_STMT | BLOCK => return, _ => {} } } - errors.extend( - node.attrs().map(|attr| SyntaxError::new(InvalidBlockAttr, attr.syntax().text_range())), - ) + if let Some(block) = expr.block() { + errors.extend( + block + .attrs() + .map(|attr| SyntaxError::new(InvalidBlockAttr, attr.syntax().text_range())), + ) + } } -- cgit v1.2.3