aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorHirokazu Hata <[email protected]>2019-01-13 12:00:27 +0000
committerHirokazu Hata <[email protected]>2019-01-13 12:10:01 +0000
commit6e73cc89b6f2e0086a3261489811f221ee7deaa8 (patch)
treeb5ebd108b601a3a89642d5ba077780f1d0bec07d /crates/ra_hir
parent6efda8f6cefdd69c3bae892eb168971a465d2a8b (diff)
Implement tuple inference
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/expr.rs13
-rw-r--r--crates/ra_hir/src/ty.rs8
2 files changed, 20 insertions, 1 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index 593fe1598..f0936e9f3 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -183,6 +183,9 @@ pub enum Expr {
183 arg_types: Vec<Option<TypeRef>>, 183 arg_types: Vec<Option<TypeRef>>,
184 body: ExprId, 184 body: ExprId,
185 }, 185 },
186 Tuple {
187 exprs: Vec<ExprId>,
188 },
186} 189}
187 190
188pub use ra_syntax::ast::PrefixOp as UnaryOp; 191pub use ra_syntax::ast::PrefixOp as UnaryOp;
@@ -297,6 +300,11 @@ impl Expr {
297 | Expr::UnaryOp { expr, .. } => { 300 | Expr::UnaryOp { expr, .. } => {
298 f(*expr); 301 f(*expr);
299 } 302 }
303 Expr::Tuple { exprs } => {
304 for expr in exprs {
305 f(*expr);
306 }
307 }
300 } 308 }
301 } 309 }
302} 310}
@@ -621,11 +629,14 @@ impl ExprCollector {
621 let op = e.op(); 629 let op = e.op();
622 self.alloc_expr(Expr::BinaryOp { lhs, rhs, op }, syntax_ptr) 630 self.alloc_expr(Expr::BinaryOp { lhs, rhs, op }, syntax_ptr)
623 } 631 }
632 ast::ExprKind::TupleExpr(e) => {
633 let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect();
634 self.alloc_expr(Expr::Tuple { exprs }, syntax_ptr)
635 }
624 636
625 // TODO implement HIR for these: 637 // TODO implement HIR for these:
626 ast::ExprKind::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), 638 ast::ExprKind::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
627 ast::ExprKind::IndexExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), 639 ast::ExprKind::IndexExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
628 ast::ExprKind::TupleExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
629 ast::ExprKind::ArrayExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), 640 ast::ExprKind::ArrayExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
630 ast::ExprKind::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), 641 ast::ExprKind::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
631 ast::ExprKind::Literal(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), 642 ast::ExprKind::Literal(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 5d5568d69..0692d3b2a 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -1040,6 +1040,14 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1040 } 1040 }
1041 _ => Ty::Unknown, 1041 _ => Ty::Unknown,
1042 }, 1042 },
1043 Expr::Tuple { exprs } => {
1044 let mut ty_vec = Vec::with_capacity(exprs.len());
1045 for arg in exprs.iter() {
1046 ty_vec.push(self.infer_expr(*arg, &Expectation::none())?);
1047 }
1048
1049 Ty::Tuple(Arc::from(ty_vec))
1050 }
1043 }; 1051 };
1044 // use a new type variable if we got Ty::Unknown here 1052 // use a new type variable if we got Ty::Unknown here
1045 let ty = self.insert_type_vars_shallow(ty); 1053 let ty = self.insert_type_vars_shallow(ty);