diff options
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 7a5485698..60c231e82 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -34,7 +34,7 @@ use test_utils::tested_by; | |||
34 | 34 | ||
35 | use crate::{ | 35 | use crate::{ |
36 | Module, Function, Struct, StructField, Enum, EnumVariant, Path, Name, ImplBlock, | 36 | Module, Function, Struct, StructField, Enum, EnumVariant, Path, Name, ImplBlock, |
37 | FnSignature, FnScopes, ModuleDef, AdtDef, | 37 | FnSignature, ExprScopes, ModuleDef, AdtDef, |
38 | db::HirDatabase, | 38 | db::HirDatabase, |
39 | type_ref::{TypeRef, Mutability}, | 39 | type_ref::{TypeRef, Mutability}, |
40 | name::KnownName, | 40 | name::KnownName, |
@@ -814,7 +814,7 @@ impl Index<PatId> for InferenceResult { | |||
814 | struct InferenceContext<'a, D: HirDatabase> { | 814 | struct InferenceContext<'a, D: HirDatabase> { |
815 | db: &'a D, | 815 | db: &'a D, |
816 | body: Arc<Body>, | 816 | body: Arc<Body>, |
817 | scopes: Arc<FnScopes>, | 817 | scopes: Arc<ExprScopes>, |
818 | module: Module, | 818 | module: Module, |
819 | impl_block: Option<ImplBlock>, | 819 | impl_block: Option<ImplBlock>, |
820 | var_unification_table: InPlaceUnificationTable<TypeVarId>, | 820 | var_unification_table: InPlaceUnificationTable<TypeVarId>, |
@@ -908,7 +908,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
908 | fn new( | 908 | fn new( |
909 | db: &'a D, | 909 | db: &'a D, |
910 | body: Arc<Body>, | 910 | body: Arc<Body>, |
911 | scopes: Arc<FnScopes>, | 911 | scopes: Arc<ExprScopes>, |
912 | module: Module, | 912 | module: Module, |
913 | impl_block: Option<ImplBlock>, | 913 | impl_block: Option<ImplBlock>, |
914 | ) -> Self { | 914 | ) -> Self { |
@@ -1488,7 +1488,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1488 | for &pat in &arm.pats { | 1488 | for &pat in &arm.pats { |
1489 | let _pat_ty = self.infer_pat(pat, &input_ty); | 1489 | let _pat_ty = self.infer_pat(pat, &input_ty); |
1490 | } | 1490 | } |
1491 | // TODO type the guard | 1491 | if let Some(guard_expr) = arm.guard { |
1492 | self.infer_expr(guard_expr, &Expectation::has_type(Ty::Bool)); | ||
1493 | } | ||
1492 | self.infer_expr(arm.expr, &expected); | 1494 | self.infer_expr(arm.expr, &expected); |
1493 | } | 1495 | } |
1494 | 1496 | ||
@@ -1561,9 +1563,17 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1561 | cast_ty | 1563 | cast_ty |
1562 | } | 1564 | } |
1563 | Expr::Ref { expr, mutability } => { | 1565 | Expr::Ref { expr, mutability } => { |
1564 | // TODO pass the expectation down | 1566 | let expectation = if let Ty::Ref(ref subty, expected_mutability) = expected.ty { |
1565 | let inner_ty = self.infer_expr(*expr, &Expectation::none()); | 1567 | if expected_mutability == Mutability::Mut && *mutability == Mutability::Shared { |
1568 | // TODO: throw type error - expected mut reference but found shared ref, | ||
1569 | // which cannot be coerced | ||
1570 | } | ||
1571 | Expectation::has_type((**subty).clone()) | ||
1572 | } else { | ||
1573 | Expectation::none() | ||
1574 | }; | ||
1566 | // TODO reference coercions etc. | 1575 | // TODO reference coercions etc. |
1576 | let inner_ty = self.infer_expr(*expr, &expectation); | ||
1567 | Ty::Ref(Arc::new(inner_ty), *mutability) | 1577 | Ty::Ref(Arc::new(inner_ty), *mutability) |
1568 | } | 1578 | } |
1569 | Expr::UnaryOp { expr, op } => { | 1579 | Expr::UnaryOp { expr, op } => { |
@@ -1720,7 +1730,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1720 | pub fn infer(db: &impl HirDatabase, func: Function) -> Arc<InferenceResult> { | 1730 | pub fn infer(db: &impl HirDatabase, func: Function) -> Arc<InferenceResult> { |
1721 | db.check_canceled(); | 1731 | db.check_canceled(); |
1722 | let body = func.body(db); | 1732 | let body = func.body(db); |
1723 | let scopes = db.fn_scopes(func); | 1733 | let scopes = db.expr_scopes(func); |
1724 | let module = func.module(db); | 1734 | let module = func.module(db); |
1725 | let impl_block = func.impl_block(db); | 1735 | let impl_block = func.impl_block(db); |
1726 | let mut ctx = InferenceContext::new(db, body, scopes, module, impl_block); | 1736 | let mut ctx = InferenceContext::new(db, body, scopes, module, impl_block); |