diff options
author | Aleksey Kladov <[email protected]> | 2019-09-02 19:41:50 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-09-02 19:52:06 +0100 |
commit | e94587e3153b52684fd3f6b82c8e7efc09ff5c8d (patch) | |
tree | 6d268b721027a5350928a6c5a0ec227b5fde8ebc /crates/ra_syntax/src/ast | |
parent | 5e3f291195b580580be7ce5622f54ebca75fb9f0 (diff) |
fix assists
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r-- | crates/ra_syntax/src/ast/expr_extensions.rs | 20 |
1 files changed, 20 insertions, 0 deletions
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 { | |||
289 | } | 289 | } |
290 | } | 290 | } |
291 | 291 | ||
292 | impl ast::BlockExpr { | ||
293 | /// false if the block is an intrinsic part of the syntax and can't be | ||
294 | /// replaced with arbitrary expression. | ||
295 | /// | ||
296 | /// ```not_rust | ||
297 | /// fn foo() { not_stand_alone } | ||
298 | /// const FOO: () = { stand_alone }; | ||
299 | /// ``` | ||
300 | pub fn is_standalone(&self) -> bool { | ||
301 | let kind = match self.syntax().parent() { | ||
302 | None => return true, | ||
303 | Some(it) => it.kind(), | ||
304 | }; | ||
305 | match kind { | ||
306 | FN_DEF | MATCH_ARM | IF_EXPR | WHILE_EXPR | LOOP_EXPR | TRY_BLOCK_EXPR => false, | ||
307 | _ => true, | ||
308 | } | ||
309 | } | ||
310 | } | ||
311 | |||
292 | #[test] | 312 | #[test] |
293 | fn test_literal_with_attr() { | 313 | fn test_literal_with_attr() { |
294 | let parse = ast::SourceFile::parse(r#"const _: &str = { #[attr] "Hello" };"#); | 314 | let parse = ast::SourceFile::parse(r#"const _: &str = { #[attr] "Hello" };"#); |