aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/ty.rs30
-rw-r--r--crates/ra_hir/src/ty/tests.rs5
2 files changed, 32 insertions, 3 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 324df5ef9..a13356714 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -876,6 +876,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
876 // a Ty itself 876 // a Ty itself
877 fn infer_pat(&mut self, pat: PatId, expected: &Expectation) -> Ty { 877 fn infer_pat(&mut self, pat: PatId, expected: &Expectation) -> Ty {
878 let body = Arc::clone(&self.body); // avoid borrow checker problem 878 let body = Arc::clone(&self.body); // avoid borrow checker problem
879
879 match (&body[pat], &expected.ty) { 880 match (&body[pat], &expected.ty) {
880 (Pat::Tuple(ref args), &Ty::Tuple(ref tuple_args)) 881 (Pat::Tuple(ref args), &Ty::Tuple(ref tuple_args))
881 if args.len() == tuple_args.len() => 882 if args.len() == tuple_args.len() =>
@@ -890,6 +891,31 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
890 { 891 {
891 self.infer_pat(pat, &Expectation::has_type((&**sub_ty).clone())); 892 self.infer_pat(pat, &Expectation::has_type((&**sub_ty).clone()));
892 } 893 }
894 (pattern, &Ty::Adt { def_id, .. }) => {
895 let adt_def = def_id.resolve(self.db);
896 match (pattern, adt_def) {
897 (&Pat::Struct, Def::Struct(s)) => {}
898 (
899 &Pat::TupleStruct {
900 path: ref p,
901 args: ref sub_pats,
902 },
903 Def::Enum(ref e),
904 ) => {
905 // TODO: resolve enum
906 }
907 (
908 &Pat::TupleStruct {
909 path: ref p,
910 args: ref sub_pats,
911 },
912 Def::EnumVariant(ref e),
913 ) => {
914 let variant_data = self.db.enum_variant_data(e.def_id);
915 }
916 _ => {}
917 }
918 }
893 // TODO: implement more 919 // TODO: implement more
894 (_, ref _expected_ty) => {} 920 (_, ref _expected_ty) => {}
895 }; 921 };
@@ -1197,7 +1223,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1197 decl_ty 1223 decl_ty
1198 }; 1224 };
1199 1225
1200 self.infer_pat(*pat, &Expectation::has_type(ty))?; 1226 self.infer_pat(*pat, &Expectation::has_type(ty));
1201 } 1227 }
1202 Statement::Expr(expr) => { 1228 Statement::Expr(expr) => {
1203 self.infer_expr(*expr, &Expectation::none()); 1229 self.infer_expr(*expr, &Expectation::none());
@@ -1218,7 +1244,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1218 let ty = self.make_ty(type_ref); 1244 let ty = self.make_ty(type_ref);
1219 let ty = self.insert_type_vars(ty); 1245 let ty = self.insert_type_vars(ty);
1220 1246
1221 self.infer_pat(*pat, &Expectation::has_type(ty))?; 1247 self.infer_pat(*pat, &Expectation::has_type(ty));
1222 } 1248 }
1223 self.return_ty = { 1249 self.return_ty = {
1224 let ty = self.make_ty(signature.ret_type()); 1250 let ty = self.make_ty(signature.ret_type());
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index a55551cbb..ff2c8b0d4 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -362,7 +362,10 @@ fn test(x: &str, y: isize) {
362fn infer_pattern() { 362fn infer_pattern() {
363 check_inference( 363 check_inference(
364 r#" 364 r#"
365enum E { A { x: usize }, B } 365enum E {
366 A { x: usize },
367 B
368}
366 369
367fn test(x: &i32) { 370fn test(x: &i32) {
368 let y = x; 371 let y = x;