From dcf8e895038a7677711b8168ee12e1d47f6018bc Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 2 Sep 2019 19:42:14 +0300 Subject: fix generated AST --- crates/ra_syntax/src/ast/generated.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 7f91417c5..fd85a3231 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -1003,7 +1003,7 @@ impl FnDef { pub fn param_list(&self) -> Option { AstChildren::new(&self.syntax).next() } - pub fn body(&self) -> Option { + pub fn body(&self) -> Option { AstChildren::new(&self.syntax).next() } pub fn ret_type(&self) -> Option { -- cgit v1.2.3 From 5e3f291195b580580be7ce5622f54ebca75fb9f0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 2 Sep 2019 21:23:19 +0300 Subject: fix hir for new block syntax --- crates/ra_syntax/src/ast/expr_extensions.rs | 6 +++--- crates/ra_syntax/src/ast/generated.rs | 2 +- crates/ra_syntax/src/ast/traits.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index d7ea4354d..1324965cf 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -9,12 +9,12 @@ use crate::{ #[derive(Debug, Clone, PartialEq, Eq)] pub enum ElseBranch { - Block(ast::Block), + Block(ast::BlockExpr), IfExpr(ast::IfExpr), } impl ast::IfExpr { - pub fn then_branch(&self) -> Option { + pub fn then_branch(&self) -> Option { self.blocks().nth(0) } pub fn else_branch(&self) -> Option { @@ -28,7 +28,7 @@ impl ast::IfExpr { Some(res) } - fn blocks(&self) -> AstChildren { + fn blocks(&self) -> AstChildren { children(self) } } diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index fd85a3231..e2a92ae60 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -3135,7 +3135,7 @@ impl AstNode for TryBlockExpr { } } impl TryBlockExpr { - pub fn block(&self) -> Option { + pub fn body(&self) -> Option { AstChildren::new(&self.syntax).next() } } diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index 20c251fba..c3e676d4c 100644 --- a/crates/ra_syntax/src/ast/traits.rs +++ b/crates/ra_syntax/src/ast/traits.rs @@ -28,7 +28,7 @@ pub trait VisibilityOwner: AstNode { } pub trait LoopBodyOwner: AstNode { - fn loop_body(&self) -> Option { + fn loop_body(&self) -> Option { child_opt(self) } } -- cgit v1.2.3 From e94587e3153b52684fd3f6b82c8e7efc09ff5c8d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 2 Sep 2019 21:41:50 +0300 Subject: fix assists --- crates/ra_syntax/src/ast/expr_extensions.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 1324965cf..25dbd0bed 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -289,6 +289,26 @@ impl ast::Literal { } } +impl ast::BlockExpr { + /// false if the block is an intrinsic part of the syntax and can't be + /// replaced with arbitrary expression. + /// + /// ```not_rust + /// fn foo() { not_stand_alone } + /// const FOO: () = { stand_alone }; + /// ``` + pub fn is_standalone(&self) -> bool { + let kind = match self.syntax().parent() { + None => return true, + Some(it) => it.kind(), + }; + match kind { + FN_DEF | MATCH_ARM | IF_EXPR | WHILE_EXPR | LOOP_EXPR | TRY_BLOCK_EXPR => false, + _ => true, + } + } +} + #[test] fn test_literal_with_attr() { let parse = ast::SourceFile::parse(r#"const _: &str = { #[attr] "Hello" };"#); -- cgit v1.2.3