Split pattern inference into more functions

This commit is contained in:
Lukas Wirth 2023-03-03 10:23:20 +01:00
parent fc2b395e00
commit ec273c3d12
6 changed files with 234 additions and 172 deletions

View file

@ -144,44 +144,6 @@ impl Default for BindingMode {
}
}
/// Used to generalize patterns and assignee expressions.
trait PatLike: Into<ExprOrPatId> + Copy {
type BindingMode: Copy;
fn infer(
this: &mut InferenceContext<'_>,
id: Self,
expected_ty: &Ty,
default_bm: Self::BindingMode,
) -> Ty;
}
impl PatLike for ExprId {
type BindingMode = ();
fn infer(
this: &mut InferenceContext<'_>,
id: Self,
expected_ty: &Ty,
_: Self::BindingMode,
) -> Ty {
this.infer_assignee_expr(id, expected_ty)
}
}
impl PatLike for PatId {
type BindingMode = BindingMode;
fn infer(
this: &mut InferenceContext<'_>,
id: Self,
expected_ty: &Ty,
default_bm: Self::BindingMode,
) -> Ty {
this.infer_pat(id, expected_ty, default_bm)
}
}
#[derive(Debug)]
pub(crate) struct InferOk<T> {
value: T,
@ -581,7 +543,7 @@ impl<'a> InferenceContext<'a> {
let ty = self.insert_type_vars(ty);
let ty = self.normalize_associated_types_in(ty);
self.infer_pat(*pat, &ty, BindingMode::default());
self.infer_top_pat(*pat, &ty);
}
let error_ty = &TypeRef::Error;
let return_ty = if data.has_async_kw() {