From 07cbb7d73deed8dac3eecdbdc7e1eaf6938a6cd6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 27 Aug 2018 12:22:09 +0300 Subject: Support if-let in scopes --- crates/libsyntax2/src/ast/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'crates/libsyntax2/src/ast/mod.rs') diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs index 6217c5b74..2ebee6a4f 100644 --- a/crates/libsyntax2/src/ast/mod.rs +++ b/crates/libsyntax2/src/ast/mod.rs @@ -115,6 +115,18 @@ impl<'a> Module<'a> { } } +impl<'a> IfExpr<'a> { + pub fn then_branch(self) -> Option> { + self.blocks().nth(0) + } + pub fn else_branch(self) -> Option> { + self.blocks().nth(1) + } + fn blocks(self) -> impl Iterator> { + children(self) + } +} + fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option { children(parent).next() } -- cgit v1.2.3