diff options
Diffstat (limited to 'crates/ra_syntax/src/ast.rs')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 00c60ebf3..ab3dd1b84 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -285,13 +285,27 @@ impl LetStmt { | |||
285 | } | 285 | } |
286 | } | 286 | } |
287 | 287 | ||
288 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
289 | pub enum ElseBranchFlavor<'a> { | ||
290 | Block(&'a Block), | ||
291 | IfExpr(&'a IfExpr), | ||
292 | } | ||
293 | |||
288 | impl IfExpr { | 294 | impl IfExpr { |
289 | pub fn then_branch(&self) -> Option<&Block> { | 295 | pub fn then_branch(&self) -> Option<&Block> { |
290 | self.blocks().nth(0) | 296 | self.blocks().nth(0) |
291 | } | 297 | } |
292 | pub fn else_branch(&self) -> Option<&Block> { | 298 | pub fn else_branch(&self) -> Option<ElseBranchFlavor> { |
293 | self.blocks().nth(1) | 299 | let res = match self.blocks().nth(1) { |
300 | Some(block) => ElseBranchFlavor::Block(block), | ||
301 | None => { | ||
302 | let elif: &IfExpr = child_opt(self)?; | ||
303 | ElseBranchFlavor::IfExpr(elif) | ||
304 | } | ||
305 | }; | ||
306 | Some(res) | ||
294 | } | 307 | } |
308 | |||
295 | fn blocks(&self) -> AstChildren<Block> { | 309 | fn blocks(&self) -> AstChildren<Block> { |
296 | children(self) | 310 | children(self) |
297 | } | 311 | } |