diff options
Diffstat (limited to 'crates/ra_hir/src/ty/infer.rs')
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 7cf465266..132ee0ca2 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -207,7 +207,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
207 | fn make_ty(&mut self, type_ref: &TypeRef) -> Ty { | 207 | fn make_ty(&mut self, type_ref: &TypeRef) -> Ty { |
208 | let ty = Ty::from_hir( | 208 | let ty = Ty::from_hir( |
209 | self.db, | 209 | self.db, |
210 | // TODO use right resolver for block | 210 | // FIXME use right resolver for block |
211 | &self.resolver, | 211 | &self.resolver, |
212 | type_ref, | 212 | type_ref, |
213 | ); | 213 | ); |
@@ -414,11 +414,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
414 | return None; | 414 | return None; |
415 | } | 415 | } |
416 | Resolution::GenericParam(..) => { | 416 | Resolution::GenericParam(..) => { |
417 | // TODO associated item of generic param | 417 | // FIXME associated item of generic param |
418 | return None; | 418 | return None; |
419 | } | 419 | } |
420 | Resolution::SelfType(_) => { | 420 | Resolution::SelfType(_) => { |
421 | // TODO associated item of self type | 421 | // FIXME associated item of self type |
422 | return None; | 422 | return None; |
423 | } | 423 | } |
424 | }; | 424 | }; |
@@ -446,7 +446,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
446 | } | 446 | } |
447 | } | 447 | } |
448 | 448 | ||
449 | // TODO: Resolve associated types | 449 | // FIXME: Resolve associated types |
450 | crate::ImplItem::TypeAlias(_) => None, | 450 | crate::ImplItem::TypeAlias(_) => None, |
451 | }; | 451 | }; |
452 | match matching_def { | 452 | match matching_def { |
@@ -504,7 +504,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
504 | return (Ty::Unknown, None); | 504 | return (Ty::Unknown, None); |
505 | } | 505 | } |
506 | Some(Resolution::SelfType(..)) => { | 506 | Some(Resolution::SelfType(..)) => { |
507 | // TODO this is allowed in an impl for a struct, handle this | 507 | // FIXME this is allowed in an impl for a struct, handle this |
508 | return (Ty::Unknown, None); | 508 | return (Ty::Unknown, None); |
509 | } | 509 | } |
510 | None => return (Ty::Unknown, None), | 510 | None => return (Ty::Unknown, None), |
@@ -513,7 +513,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
513 | None => return (Ty::Unknown, None), | 513 | None => return (Ty::Unknown, None), |
514 | Some(it) => it, | 514 | Some(it) => it, |
515 | }; | 515 | }; |
516 | // TODO remove the duplication between here and `Ty::from_path`? | 516 | // FIXME remove the duplication between here and `Ty::from_path`? |
517 | let substs = Ty::substs_from_path(self.db, resolver, path, def); | 517 | let substs = Ty::substs_from_path(self.db, resolver, path, def); |
518 | match def { | 518 | match def { |
519 | TypableDef::Struct(s) => { | 519 | TypableDef::Struct(s) => { |
@@ -590,7 +590,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
590 | | Pat::Struct { .. } | 590 | | Pat::Struct { .. } |
591 | | Pat::Range { .. } | 591 | | Pat::Range { .. } |
592 | | Pat::Slice { .. } => true, | 592 | | Pat::Slice { .. } => true, |
593 | // TODO: Path/Lit might actually evaluate to ref, but inference is unimplemented. | 593 | // FIXME: Path/Lit might actually evaluate to ref, but inference is unimplemented. |
594 | Pat::Path(..) | Pat::Lit(..) => true, | 594 | Pat::Path(..) | Pat::Lit(..) => true, |
595 | Pat::Wild | Pat::Bind { .. } | Pat::Ref { .. } | Pat::Missing => false, | 595 | Pat::Wild | Pat::Bind { .. } | Pat::Ref { .. } | Pat::Missing => false, |
596 | }; | 596 | }; |
@@ -635,7 +635,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
635 | let expectation = match expected.as_reference() { | 635 | let expectation = match expected.as_reference() { |
636 | Some((inner_ty, exp_mut)) => { | 636 | Some((inner_ty, exp_mut)) => { |
637 | if *mutability != exp_mut { | 637 | if *mutability != exp_mut { |
638 | // TODO: emit type error? | 638 | // FIXME: emit type error? |
639 | } | 639 | } |
640 | inner_ty | 640 | inner_ty |
641 | } | 641 | } |
@@ -651,7 +651,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
651 | self.infer_struct_pat(p.as_ref(), fields, expected, default_bm) | 651 | self.infer_struct_pat(p.as_ref(), fields, expected, default_bm) |
652 | } | 652 | } |
653 | Pat::Path(path) => { | 653 | Pat::Path(path) => { |
654 | // TODO use correct resolver for the surrounding expression | 654 | // FIXME use correct resolver for the surrounding expression |
655 | let resolver = self.resolver.clone(); | 655 | let resolver = self.resolver.clone(); |
656 | self.infer_path_expr(&resolver, &path, pat.into()).unwrap_or(Ty::Unknown) | 656 | self.infer_path_expr(&resolver, &path, pat.into()).unwrap_or(Ty::Unknown) |
657 | } | 657 | } |
@@ -741,7 +741,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
741 | Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected), | 741 | Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected), |
742 | Expr::Loop { body } => { | 742 | Expr::Loop { body } => { |
743 | self.infer_expr(*body, &Expectation::has_type(Ty::unit())); | 743 | self.infer_expr(*body, &Expectation::has_type(Ty::unit())); |
744 | // TODO handle break with value | 744 | // FIXME handle break with value |
745 | Ty::simple(TypeCtor::Never) | 745 | Ty::simple(TypeCtor::Never) |
746 | } | 746 | } |
747 | Expr::While { condition, body } => { | 747 | Expr::While { condition, body } => { |
@@ -769,7 +769,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
769 | self.infer_pat(*arg_pat, &expected, BindingMode::default()); | 769 | self.infer_pat(*arg_pat, &expected, BindingMode::default()); |
770 | } | 770 | } |
771 | 771 | ||
772 | // TODO: infer lambda type etc. | 772 | // FIXME: infer lambda type etc. |
773 | let _body_ty = self.infer_expr(*body, &Expectation::none()); | 773 | let _body_ty = self.infer_expr(*body, &Expectation::none()); |
774 | Ty::Unknown | 774 | Ty::Unknown |
775 | } | 775 | } |
@@ -795,7 +795,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
795 | }, | 795 | }, |
796 | _ => { | 796 | _ => { |
797 | // not callable | 797 | // not callable |
798 | // TODO report an error? | 798 | // FIXME report an error? |
799 | (Vec::new(), Ty::Unknown) | 799 | (Vec::new(), Ty::Unknown) |
800 | } | 800 | } |
801 | }; | 801 | }; |
@@ -894,14 +894,14 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
894 | expected.ty | 894 | expected.ty |
895 | } | 895 | } |
896 | Expr::Path(p) => { | 896 | Expr::Path(p) => { |
897 | // TODO this could be more efficient... | 897 | // FIXME this could be more efficient... |
898 | let resolver = expr::resolver_for_expr(self.body.clone(), self.db, tgt_expr); | 898 | let resolver = expr::resolver_for_expr(self.body.clone(), self.db, tgt_expr); |
899 | self.infer_path_expr(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown) | 899 | self.infer_path_expr(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown) |
900 | } | 900 | } |
901 | Expr::Continue => Ty::simple(TypeCtor::Never), | 901 | Expr::Continue => Ty::simple(TypeCtor::Never), |
902 | Expr::Break { expr } => { | 902 | Expr::Break { expr } => { |
903 | if let Some(expr) = expr { | 903 | if let Some(expr) = expr { |
904 | // TODO handle break with value | 904 | // FIXME handle break with value |
905 | self.infer_expr(*expr, &Expectation::none()); | 905 | self.infer_expr(*expr, &Expectation::none()); |
906 | } | 906 | } |
907 | Ty::simple(TypeCtor::Never) | 907 | Ty::simple(TypeCtor::Never) |
@@ -957,21 +957,21 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
957 | Expr::Cast { expr, type_ref } => { | 957 | Expr::Cast { expr, type_ref } => { |
958 | let _inner_ty = self.infer_expr(*expr, &Expectation::none()); | 958 | let _inner_ty = self.infer_expr(*expr, &Expectation::none()); |
959 | let cast_ty = self.make_ty(type_ref); | 959 | let cast_ty = self.make_ty(type_ref); |
960 | // TODO check the cast... | 960 | // FIXME check the cast... |
961 | cast_ty | 961 | cast_ty |
962 | } | 962 | } |
963 | Expr::Ref { expr, mutability } => { | 963 | Expr::Ref { expr, mutability } => { |
964 | let expectation = | 964 | let expectation = |
965 | if let Some((exp_inner, exp_mutability)) = &expected.ty.as_reference() { | 965 | if let Some((exp_inner, exp_mutability)) = &expected.ty.as_reference() { |
966 | if *exp_mutability == Mutability::Mut && *mutability == Mutability::Shared { | 966 | if *exp_mutability == Mutability::Mut && *mutability == Mutability::Shared { |
967 | // TODO: throw type error - expected mut reference but found shared ref, | 967 | // FIXME: throw type error - expected mut reference but found shared ref, |
968 | // which cannot be coerced | 968 | // which cannot be coerced |
969 | } | 969 | } |
970 | Expectation::has_type(Ty::clone(exp_inner)) | 970 | Expectation::has_type(Ty::clone(exp_inner)) |
971 | } else { | 971 | } else { |
972 | Expectation::none() | 972 | Expectation::none() |
973 | }; | 973 | }; |
974 | // TODO reference coercions etc. | 974 | // FIXME reference coercions etc. |
975 | let inner_ty = self.infer_expr(*expr, &expectation); | 975 | let inner_ty = self.infer_expr(*expr, &expectation); |
976 | Ty::apply_one(TypeCtor::Ref(*mutability), inner_ty) | 976 | Ty::apply_one(TypeCtor::Ref(*mutability), inner_ty) |
977 | } | 977 | } |
@@ -982,7 +982,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
982 | if let Some(derefed_ty) = inner_ty.builtin_deref() { | 982 | if let Some(derefed_ty) = inner_ty.builtin_deref() { |
983 | derefed_ty | 983 | derefed_ty |
984 | } else { | 984 | } else { |
985 | // TODO Deref::deref | 985 | // FIXME Deref::deref |
986 | Ty::Unknown | 986 | Ty::Unknown |
987 | } | 987 | } |
988 | } | 988 | } |
@@ -1002,7 +1002,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1002 | Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => { | 1002 | Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => { |
1003 | inner_ty | 1003 | inner_ty |
1004 | } | 1004 | } |
1005 | // TODO: resolve ops::Neg trait | 1005 | // FIXME: resolve ops::Neg trait |
1006 | _ => Ty::Unknown, | 1006 | _ => Ty::Unknown, |
1007 | } | 1007 | } |
1008 | } | 1008 | } |
@@ -1013,7 +1013,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1013 | _ => Ty::Unknown, | 1013 | _ => Ty::Unknown, |
1014 | }, | 1014 | }, |
1015 | Ty::Infer(InferTy::IntVar(..)) => inner_ty, | 1015 | Ty::Infer(InferTy::IntVar(..)) => inner_ty, |
1016 | // TODO: resolve ops::Not trait for inner_ty | 1016 | // FIXME: resolve ops::Not trait for inner_ty |
1017 | _ => Ty::Unknown, | 1017 | _ => Ty::Unknown, |
1018 | } | 1018 | } |
1019 | } | 1019 | } |
@@ -1028,12 +1028,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1028 | _ => Expectation::none(), | 1028 | _ => Expectation::none(), |
1029 | }; | 1029 | }; |
1030 | let lhs_ty = self.infer_expr(*lhs, &lhs_expectation); | 1030 | let lhs_ty = self.infer_expr(*lhs, &lhs_expectation); |
1031 | // TODO: find implementation of trait corresponding to operation | 1031 | // FIXME: find implementation of trait corresponding to operation |
1032 | // symbol and resolve associated `Output` type | 1032 | // symbol and resolve associated `Output` type |
1033 | let rhs_expectation = op::binary_op_rhs_expectation(*op, lhs_ty); | 1033 | let rhs_expectation = op::binary_op_rhs_expectation(*op, lhs_ty); |
1034 | let rhs_ty = self.infer_expr(*rhs, &Expectation::has_type(rhs_expectation)); | 1034 | let rhs_ty = self.infer_expr(*rhs, &Expectation::has_type(rhs_expectation)); |
1035 | 1035 | ||
1036 | // TODO: similar as above, return ty is often associated trait type | 1036 | // FIXME: similar as above, return ty is often associated trait type |
1037 | op::binary_op_return_ty(*op, rhs_ty) | 1037 | op::binary_op_return_ty(*op, rhs_ty) |
1038 | } | 1038 | } |
1039 | _ => Ty::Unknown, | 1039 | _ => Ty::Unknown, |
@@ -1227,7 +1227,7 @@ impl InferTy { | |||
1227 | #[derive(Clone, PartialEq, Eq, Debug)] | 1227 | #[derive(Clone, PartialEq, Eq, Debug)] |
1228 | struct Expectation { | 1228 | struct Expectation { |
1229 | ty: Ty, | 1229 | ty: Ty, |
1230 | // TODO: In some cases, we need to be aware whether the expectation is that | 1230 | // FIXME: In some cases, we need to be aware whether the expectation is that |
1231 | // the type match exactly what we passed, or whether it just needs to be | 1231 | // the type match exactly what we passed, or whether it just needs to be |
1232 | // coercible to the expected type. See Expectation::rvalue_hint in rustc. | 1232 | // coercible to the expected type. See Expectation::rvalue_hint in rustc. |
1233 | } | 1233 | } |