Unnamed repository; edit this file 'description' to name the repository.
The type of a binding in a `Pat::Bind` is the expected type, not the inferred type of the pattern
The inferred type is reconstructed with match ergonomics, e.g. matching against `(&&i32, &&i32)` could give `(i32, i32)`), but we of course cannot bind to that.
Chayim Refael Friedman 5 months ago
parent 9e729cc · commit d58ea7d
-rw-r--r--crates/hir-ty/src/infer/pat.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/crates/hir-ty/src/infer/pat.rs b/crates/hir-ty/src/infer/pat.rs
index 1f7465c7d9..c0ca855617 100644
--- a/crates/hir-ty/src/infer/pat.rs
+++ b/crates/hir-ty/src/infer/pat.rs
@@ -469,9 +469,9 @@ impl<'db> InferenceContext<'_, 'db> {
let bound_ty = match mode {
BindingMode::Ref(mutability) => {
let inner_lt = self.table.next_region_var();
- Ty::new_ref(self.interner(), inner_lt, inner_ty, mutability)
+ Ty::new_ref(self.interner(), inner_lt, expected, mutability)
}
- BindingMode::Move => inner_ty,
+ BindingMode::Move => expected,
};
self.write_pat_ty(pat, inner_ty);
self.write_binding_ty(binding, bound_ty);