impl Default for BindingMode.
This decouples callers from knowing what the default binding mode of pattern matching is.
This commit is contained in:
parent
b42c5ced68
commit
354134ffb4
@ -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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user