From 354134ffb4e6a0962e9faf19ebe2bb1cda4da9ab Mon Sep 17 00:00:00 2001 From: Michael Killough Date: Sun, 17 Mar 2019 18:46:01 +0000 Subject: [PATCH] impl Default for BindingMode. This decouples callers from knowing what the default binding mode of pattern matching is. --- crates/ra_hir/src/ty/infer.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 7200446bad8..92c79df1567 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -81,6 +81,12 @@ pub fn convert(annotation: &BindingAnnotation) -> BindingMode { } } +impl Default for BindingMode { + fn default() -> Self { + BindingMode::Move + } +} + /// The result of type inference: A mapping from expressions and patterns to types. #[derive(Clone, PartialEq, Eq, Debug)] pub struct InferenceResult { @@ -761,7 +767,7 @@ fn infer_expr(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty { } Expr::For { iterable, body, pat } => { let _iterable_ty = self.infer_expr(*iterable, &Expectation::none()); - self.infer_pat(*pat, &Ty::Unknown, BindingMode::Move); + self.infer_pat(*pat, &Ty::Unknown, BindingMode::default()); self.infer_expr(*body, &Expectation::has_type(Ty::unit())); Ty::unit() } @@ -775,7 +781,7 @@ fn infer_expr(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty { } else { Ty::Unknown }; - self.infer_pat(*arg_pat, &expected, BindingMode::Move); + self.infer_pat(*arg_pat, &expected, BindingMode::default()); } // TODO: infer lambda type etc. @@ -865,7 +871,7 @@ fn infer_expr(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty { for arm in arms { for &pat in &arm.pats { - let _pat_ty = self.infer_pat(pat, &input_ty, BindingMode::Move); + let _pat_ty = self.infer_pat(pat, &input_ty, BindingMode::default()); } if let Some(guard_expr) = arm.guard { self.infer_expr(guard_expr, &Expectation::has_type(Ty::Bool)); @@ -1065,7 +1071,7 @@ fn infer_block( decl_ty }; - self.infer_pat(*pat, &ty, BindingMode::Move); + self.infer_pat(*pat, &ty, BindingMode::default()); } Statement::Expr(expr) => { self.infer_expr(*expr, &Expectation::none()); @@ -1081,7 +1087,7 @@ fn collect_fn_signature(&mut self, signature: &FnSignature) { for (type_ref, pat) in signature.params().iter().zip(body.params()) { let ty = self.make_ty(type_ref); - self.infer_pat(*pat, &ty, BindingMode::Move); + self.infer_pat(*pat, &ty, BindingMode::default()); } self.return_ty = self.make_ty(signature.ret_type()); }