aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/expr_extensions.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-09 21:22:58 +0100
committerAleksey Kladov <[email protected]>2020-04-09 21:22:58 +0100
commite07d3c94de4694f38aa87316018c0d4cf28be941 (patch)
treeae30dc5d6752f765b1ccefdcfd8af079a630133e /crates/ra_syntax/src/ast/expr_extensions.rs
parent33df20868da38ca47f22f8bfab36dd4c965cf333 (diff)
Remove code duplication
Diffstat (limited to 'crates/ra_syntax/src/ast/expr_extensions.rs')
-rw-r--r--crates/ra_syntax/src/ast/expr_extensions.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs
index 40c8fca3b..003ee00b3 100644
--- a/crates/ra_syntax/src/ast/expr_extensions.rs
+++ b/crates/ra_syntax/src/ast/expr_extensions.rs
@@ -1,7 +1,7 @@
1//! Various extension methods to ast Expr Nodes, which are hard to code-generate. 1//! Various extension methods to ast Expr Nodes, which are hard to code-generate.
2 2
3use crate::{ 3use crate::{
4 ast::{self, child_opt, children, AstChildren, AstNode}, 4 ast::{self, support, AstChildren, AstNode},
5 SmolStr, 5 SmolStr,
6 SyntaxKind::*, 6 SyntaxKind::*,
7 SyntaxToken, T, 7 SyntaxToken, T,
@@ -36,7 +36,7 @@ impl ast::IfExpr {
36 let res = match self.blocks().nth(1) { 36 let res = match self.blocks().nth(1) {
37 Some(block) => ElseBranch::Block(block), 37 Some(block) => ElseBranch::Block(block),
38 None => { 38 None => {
39 let elif: ast::IfExpr = child_opt(self)?; 39 let elif: ast::IfExpr = support::child(self.syntax())?;
40 ElseBranch::IfExpr(elif) 40 ElseBranch::IfExpr(elif)
41 } 41 }
42 }; 42 };
@@ -44,7 +44,7 @@ impl ast::IfExpr {
44 } 44 }
45 45
46 fn blocks(&self) -> AstChildren<ast::BlockExpr> { 46 fn blocks(&self) -> AstChildren<ast::BlockExpr> {
47 children(self) 47 support::children(self.syntax())
48 } 48 }
49} 49}
50 50
@@ -212,15 +212,15 @@ impl ast::BinExpr {
212 } 212 }
213 213
214 pub fn lhs(&self) -> Option<ast::Expr> { 214 pub fn lhs(&self) -> Option<ast::Expr> {
215 children(self).next() 215 support::children(self.syntax()).next()
216 } 216 }
217 217
218 pub fn rhs(&self) -> Option<ast::Expr> { 218 pub fn rhs(&self) -> Option<ast::Expr> {
219 children(self).nth(1) 219 support::children(self.syntax()).nth(1)
220 } 220 }
221 221
222 pub fn sub_exprs(&self) -> (Option<ast::Expr>, Option<ast::Expr>) { 222 pub fn sub_exprs(&self) -> (Option<ast::Expr>, Option<ast::Expr>) {
223 let mut children = children(self); 223 let mut children = support::children(self.syntax());
224 let first = children.next(); 224 let first = children.next();
225 let second = children.next(); 225 let second = children.next();
226 (first, second) 226 (first, second)
@@ -275,10 +275,10 @@ impl ast::RangeExpr {
275 275
276impl ast::IndexExpr { 276impl ast::IndexExpr {
277 pub fn base(&self) -> Option<ast::Expr> { 277 pub fn base(&self) -> Option<ast::Expr> {
278 children(self).next() 278 support::children(self.syntax()).next()
279 } 279 }
280 pub fn index(&self) -> Option<ast::Expr> { 280 pub fn index(&self) -> Option<ast::Expr> {
281 children(self).nth(1) 281 support::children(self.syntax()).nth(1)
282 } 282 }
283} 283}
284 284
@@ -291,11 +291,11 @@ impl ast::ArrayExpr {
291 pub fn kind(&self) -> ArrayExprKind { 291 pub fn kind(&self) -> ArrayExprKind {
292 if self.is_repeat() { 292 if self.is_repeat() {
293 ArrayExprKind::Repeat { 293 ArrayExprKind::Repeat {
294 initializer: children(self).next(), 294 initializer: support::children(self.syntax()).next(),
295 repeat: children(self).nth(1), 295 repeat: support::children(self.syntax()).nth(1),
296 } 296 }
297 } else { 297 } else {
298 ArrayExprKind::ElementList(children(self)) 298 ArrayExprKind::ElementList(support::children(self.syntax()))
299 } 299 }
300 } 300 }
301 301