aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/infer.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-08-17 16:57:02 +0100
committerGitHub <[email protected]>2019-08-17 16:57:02 +0100
commit5a2a97c7e8cfac690a00505d8644be30f7ee863a (patch)
treeeba980071d5c8941fdd3adc11fc5525d243ba2b3 /crates/ra_hir/src/ty/infer.rs
parentd15cf2c9600e0464b9bcd0273e7845efbf7bdeb5 (diff)
parent189d879659f4e44c3343023d6455bed7cdf0e7c9 (diff)
Merge #1694
1694: Implement initial type-inference support for Index r=flodiebold a=matklad This doesn't actually infer indexing types, but at least it walks sub-expressions! Initially, I wanted to make `Index` just a new kind of `BinOp` (b/c indexing is kind of a binary op), so I've refactoring binop handing a bit. However, in the end I've decided to add a separate expr kind for Index, because `foo[0]`, `&foo[1]` and `&mut foo[1]` all seem to need slightly different handing, which is not binop-like r? @flodiebold Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty/infer.rs')
-rw-r--r--crates/ra_hir/src/ty/infer.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 675df4a22..cca59538a 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -1265,9 +1265,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1265 Expr::BinaryOp { lhs, rhs, op } => match op { 1265 Expr::BinaryOp { lhs, rhs, op } => match op {
1266 Some(op) => { 1266 Some(op) => {
1267 let lhs_expectation = match op { 1267 let lhs_expectation = match op {
1268 BinaryOp::BooleanAnd | BinaryOp::BooleanOr => { 1268 BinaryOp::LogicOp(..) => Expectation::has_type(Ty::simple(TypeCtor::Bool)),
1269 Expectation::has_type(Ty::simple(TypeCtor::Bool))
1270 }
1271 _ => Expectation::none(), 1269 _ => Expectation::none(),
1272 }; 1270 };
1273 let lhs_ty = self.infer_expr(*lhs, &lhs_expectation); 1271 let lhs_ty = self.infer_expr(*lhs, &lhs_expectation);
@@ -1281,6 +1279,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1281 } 1279 }
1282 _ => Ty::Unknown, 1280 _ => Ty::Unknown,
1283 }, 1281 },
1282 Expr::Index { base, index } => {
1283 let _base_ty = self.infer_expr(*base, &Expectation::none());
1284 let _index_ty = self.infer_expr(*index, &Expectation::none());
1285 // FIXME: use `std::ops::Index::Output` to figure out the real return type
1286 Ty::Unknown
1287 }
1284 Expr::Tuple { exprs } => { 1288 Expr::Tuple { exprs } => {
1285 let mut ty_vec = Vec::with_capacity(exprs.len()); 1289 let mut ty_vec = Vec::with_capacity(exprs.len());
1286 for arg in exprs.iter() { 1290 for arg in exprs.iter() {