aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty.rs
diff options
context:
space:
mode:
authorMarcus Klaas de Vries <[email protected]>2019-01-17 12:08:18 +0000
committerAleksey Kladov <[email protected]>2019-01-19 12:37:26 +0000
commitd48d5b8b6ca59b462b3a84dad9868daff2eddb6d (patch)
tree20f1936ccf07abea463ae81b36132efd76ad4f71 /crates/ra_hir/src/ty.rs
parent9433a108cfcf3a9c7de9299d6641a5abf9031a17 (diff)
Add initial (flawed) implementation of binding annotations
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r--crates/ra_hir/src/ty.rs26
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