diff options
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 8ad80990e..bc842dd26 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -37,7 +37,7 @@ use crate::{ | |||
37 | db::HirDatabase, | 37 | db::HirDatabase, |
38 | type_ref::{TypeRef, Mutability}, | 38 | type_ref::{TypeRef, Mutability}, |
39 | name::KnownName, | 39 | name::KnownName, |
40 | expr::{Body, Expr, MatchArm, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, FieldPat}, | 40 | expr::{Body, Expr, BindingAnnotation, MatchArm, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, FieldPat}, |
41 | }; | 41 | }; |
42 | 42 | ||
43 | /// The ID of a type variable. | 43 | /// The ID of a type variable. |
@@ -985,6 +985,30 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
985 | path: ref p, | 985 | path: ref p, |
986 | args: ref fields, | 986 | args: ref fields, |
987 | } => self.infer_struct(p.as_ref(), fields), | 987 | } => self.infer_struct(p.as_ref(), fields), |
988 | Pat::Path(path) => { | ||
989 | // is this right? | ||
990 | self.module | ||
991 | .resolve_path(self.db, &path) | ||
992 | .take_values() | ||
993 | .map_or(Ty::Unknown, |resolved| self.db.type_for_def(resolved)) | ||
994 | } | ||
995 | Pat::Bind { | ||
996 | mode, | ||
997 | name: _name, | ||
998 | sub_pat, | ||
999 | } => { | ||
1000 | let subty = if let Some(subpat) = sub_pat { | ||
1001 | self.infer_pat(*subpat, expected) | ||
1002 | } else { | ||
1003 | Ty::Unknown | ||
1004 | }; | ||
1005 | |||
1006 | match mode { | ||
1007 | BindingAnnotation::Ref => Ty::Ref(subty.into(), Mutability::Shared), | ||
1008 | BindingAnnotation::RefMut => Ty::Ref(subty.into(), Mutability::Mut), | ||
1009 | BindingAnnotation::Mutable | BindingAnnotation::Unannotated => subty, | ||
1010 | } | ||
1011 | } | ||
988 | _ => Ty::Unknown, | 1012 | _ => Ty::Unknown, |
989 | }; | 1013 | }; |
990 | // use a new type variable if we got Ty::Unknown here | 1014 | // use a new type variable if we got Ty::Unknown here |