diff options
author | Lenard Pratt <[email protected]> | 2019-04-03 23:23:58 +0100 |
---|---|---|
committer | Lenard Pratt <[email protected]> | 2019-04-07 13:23:12 +0100 |
commit | 2d73c909fe03c799b488aa0f97a588e13bbd7006 (patch) | |
tree | b96bf7ccc6cc6e0ebb86e52ffad104f44f53d556 /crates/ra_hir/src/expr.rs | |
parent | 36f5d997565b6390a4b524e7e1d0d805f0f26bdb (diff) |
Added inference of array length
Diffstat (limited to 'crates/ra_hir/src/expr.rs')
-rw-r--r-- | crates/ra_hir/src/expr.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index cfa824458..3e6578651 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -240,6 +240,7 @@ pub enum Expr { | |||
240 | }, | 240 | }, |
241 | Array { | 241 | Array { |
242 | exprs: Vec<ExprId>, | 242 | exprs: Vec<ExprId>, |
243 | repeat: Option<ExprId>, | ||
243 | }, | 244 | }, |
244 | Literal(Literal), | 245 | Literal(Literal), |
245 | } | 246 | } |
@@ -348,11 +349,20 @@ impl Expr { | |||
348 | | Expr::UnaryOp { expr, .. } => { | 349 | | Expr::UnaryOp { expr, .. } => { |
349 | f(*expr); | 350 | f(*expr); |
350 | } | 351 | } |
351 | Expr::Tuple { exprs } | Expr::Array { exprs } => { | 352 | Expr::Tuple { exprs } => { |
352 | for expr in exprs { | 353 | for expr in exprs { |
353 | f(*expr); | 354 | f(*expr); |
354 | } | 355 | } |
355 | } | 356 | } |
357 | Expr::Array { exprs, repeat } => { | ||
358 | for expr in exprs { | ||
359 | f(*expr); | ||
360 | } | ||
361 | |||
362 | if let Some(expr) = repeat { | ||
363 | f(*expr) | ||
364 | } | ||
365 | } | ||
356 | Expr::Literal(_) => {} | 366 | Expr::Literal(_) => {} |
357 | } | 367 | } |
358 | } | 368 | } |
@@ -725,7 +735,8 @@ impl ExprCollector { | |||
725 | } | 735 | } |
726 | ast::ExprKind::ArrayExpr(e) => { | 736 | ast::ExprKind::ArrayExpr(e) => { |
727 | let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect(); | 737 | let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect(); |
728 | self.alloc_expr(Expr::Array { exprs }, syntax_ptr) | 738 | let repeat = e.repeat().map(|e| self.collect_expr(e)); |
739 | self.alloc_expr(Expr::Array { exprs, repeat }, syntax_ptr) | ||
729 | } | 740 | } |
730 | ast::ExprKind::Literal(e) => { | 741 | ast::ExprKind::Literal(e) => { |
731 | let lit = match e.kind() { | 742 | let lit = match e.kind() { |