diff options
author | Michael Killough <[email protected]> | 2019-03-17 18:46:01 +0000 |
---|---|---|
committer | Michael Killough <[email protected]> | 2019-03-17 18:46:01 +0000 |
commit | 354134ffb4e6a0962e9faf19ebe2bb1cda4da9ab (patch) | |
tree | 0e5c4afc14678572b3d4e45718bf72aa52fd0e8f /crates/ra_hir | |
parent | b42c5ced68c019108e079dc01d0bd29606efc10c (diff) |
impl Default for BindingMode.
This decouples callers from knowing what the default binding mode of
pattern matching is.
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 7200446ba..92c79df15 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -81,6 +81,12 @@ impl BindingMode { | |||
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | impl Default for BindingMode { | ||
85 | fn default() -> Self { | ||
86 | BindingMode::Move | ||
87 | } | ||
88 | } | ||
89 | |||
84 | /// The result of type inference: A mapping from expressions and patterns to types. | 90 | /// The result of type inference: A mapping from expressions and patterns to types. |
85 | #[derive(Clone, PartialEq, Eq, Debug)] | 91 | #[derive(Clone, PartialEq, Eq, Debug)] |
86 | pub struct InferenceResult { | 92 | pub struct InferenceResult { |
@@ -761,7 +767,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
761 | } | 767 | } |
762 | Expr::For { iterable, body, pat } => { | 768 | Expr::For { iterable, body, pat } => { |
763 | let _iterable_ty = self.infer_expr(*iterable, &Expectation::none()); | 769 | let _iterable_ty = self.infer_expr(*iterable, &Expectation::none()); |
764 | self.infer_pat(*pat, &Ty::Unknown, BindingMode::Move); | 770 | self.infer_pat(*pat, &Ty::Unknown, BindingMode::default()); |
765 | self.infer_expr(*body, &Expectation::has_type(Ty::unit())); | 771 | self.infer_expr(*body, &Expectation::has_type(Ty::unit())); |
766 | Ty::unit() | 772 | Ty::unit() |
767 | } | 773 | } |
@@ -775,7 +781,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
775 | } else { | 781 | } else { |
776 | Ty::Unknown | 782 | Ty::Unknown |
777 | }; | 783 | }; |
778 | self.infer_pat(*arg_pat, &expected, BindingMode::Move); | 784 | self.infer_pat(*arg_pat, &expected, BindingMode::default()); |
779 | } | 785 | } |
780 | 786 | ||
781 | // TODO: infer lambda type etc. | 787 | // TODO: infer lambda type etc. |
@@ -865,7 +871,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
865 | 871 | ||
866 | for arm in arms { | 872 | for arm in arms { |
867 | for &pat in &arm.pats { | 873 | for &pat in &arm.pats { |
868 | let _pat_ty = self.infer_pat(pat, &input_ty, BindingMode::Move); | 874 | let _pat_ty = self.infer_pat(pat, &input_ty, BindingMode::default()); |
869 | } | 875 | } |
870 | if let Some(guard_expr) = arm.guard { | 876 | if let Some(guard_expr) = arm.guard { |
871 | self.infer_expr(guard_expr, &Expectation::has_type(Ty::Bool)); | 877 | self.infer_expr(guard_expr, &Expectation::has_type(Ty::Bool)); |
@@ -1065,7 +1071,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1065 | decl_ty | 1071 | decl_ty |
1066 | }; | 1072 | }; |
1067 | 1073 | ||
1068 | self.infer_pat(*pat, &ty, BindingMode::Move); | 1074 | self.infer_pat(*pat, &ty, BindingMode::default()); |
1069 | } | 1075 | } |
1070 | Statement::Expr(expr) => { | 1076 | Statement::Expr(expr) => { |
1071 | self.infer_expr(*expr, &Expectation::none()); | 1077 | self.infer_expr(*expr, &Expectation::none()); |
@@ -1081,7 +1087,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1081 | for (type_ref, pat) in signature.params().iter().zip(body.params()) { | 1087 | for (type_ref, pat) in signature.params().iter().zip(body.params()) { |
1082 | let ty = self.make_ty(type_ref); | 1088 | let ty = self.make_ty(type_ref); |
1083 | 1089 | ||
1084 | self.infer_pat(*pat, &ty, BindingMode::Move); | 1090 | self.infer_pat(*pat, &ty, BindingMode::default()); |
1085 | } | 1091 | } |
1086 | self.return_ty = self.make_ty(signature.ret_type()); | 1092 | self.return_ty = self.make_ty(signature.ret_type()); |
1087 | } | 1093 | } |