diff options
Diffstat (limited to 'crates/ra_syntax/src')
-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" };"#); |