Skip to content

Commit 1962be3

Browse files
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.
1 parent a0b8112 commit 1962be3

File tree

1 file changed

+2
-2
lines changed
  • src/tools/rust-analyzer/crates/hir-ty/src/infer

1 file changed

+2
-2
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/infer/pat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,9 @@ impl<'db> InferenceContext<'_, 'db> {
469469
let bound_ty = match mode {
470470
BindingMode::Ref(mutability) => {
471471
let inner_lt = self.table.next_region_var();
472-
Ty::new_ref(self.interner(), inner_lt, inner_ty, mutability)
472+
Ty::new_ref(self.interner(), inner_lt, expected, mutability)
473473
}
474-
BindingMode::Move => inner_ty,
474+
BindingMode::Move => expected,
475475
};
476476
self.write_pat_ty(pat, inner_ty);
477477
self.write_binding_ty(binding, bound_ty);

0 commit comments

Comments
 (0)