]> git.lizzy.rs Git - rust.git/commitdiff
impl Default for BindingMode.
authorMichael Killough <michaeljkillough@gmail.com>
Sun, 17 Mar 2019 18:46:01 +0000 (18:46 +0000)
committerMichael Killough <michaeljkillough@gmail.com>
Sun, 17 Mar 2019 18:46:01 +0000 (18:46 +0000)
This decouples callers from knowing what the default binding mode of
pattern matching is.

crates/ra_hir/src/ty/infer.rs

index 7200446bad8beedb13f850a7b45eb32f8901217f..92c79df156794955bc0de4cc45a0243285e60ef0 100644 (file)
@@ -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());
     }