Skip to content

Commit 5193728

Browse files
bors[bot]Veykril
andauthored
Merge #9114
9114: Fix bind patterns always being treated as ref taking patterns r=Veykril a=Veykril Fixes #9107 bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 parents 5be653d + ded4e7c commit 5193728

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

crates/hir_ty/src/infer/pat.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ fn is_non_ref_pat(body: &hir_def::body::Body, pat: PatId) -> bool {
290290
Expr::Literal(Literal::String(..)) => false,
291291
_ => true,
292292
},
293+
Pat::Bind { mode: BindingAnnotation::Mutable, subpat: Some(subpat), .. }
294+
| Pat::Bind { mode: BindingAnnotation::Unannotated, subpat: Some(subpat), .. } => {
295+
is_non_ref_pat(body, *subpat)
296+
}
293297
Pat::Wild | Pat::Bind { .. } | Pat::Ref { .. } | Pat::Box { .. } | Pat::Missing => false,
294298
}
295299
}

crates/hir_ty/src/tests/patterns.rs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ fn infer_pattern() {
2020
let h = val;
2121
}
2222
23+
if let x @ true = &true {}
24+
2325
let lambda = |a: u64, b, c: i32| { a + b; c };
2426
2527
let ref ref_to_x = x;
@@ -30,7 +32,7 @@ fn infer_pattern() {
3032
"#,
3133
expect![[r#"
3234
8..9 'x': &i32
33-
17..368 '{ ...o_x; }': ()
35+
17..400 '{ ...o_x; }': ()
3436
27..28 'y': &i32
3537
31..32 'x': &i32
3638
42..44 '&z': &i32
@@ -59,24 +61,31 @@ fn infer_pattern() {
5961
176..204 '{ ... }': ()
6062
190..191 'h': {unknown}
6163
194..197 'val': {unknown}
62-
214..220 'lambda': |u64, u64, i32| -> i32
63-
223..255 '|a: u6...b; c }': |u64, u64, i32| -> i32
64-
224..225 'a': u64
65-
232..233 'b': u64
66-
235..236 'c': i32
67-
243..255 '{ a + b; c }': i32
68-
245..246 'a': u64
69-
245..250 'a + b': u64
70-
249..250 'b': u64
71-
252..253 'c': i32
72-
266..278 'ref ref_to_x': &&i32
73-
281..282 'x': &i32
74-
292..301 'mut mut_x': &i32
75-
304..305 'x': &i32
76-
315..335 'ref mu...f_to_x': &mut &i32
77-
338..339 'x': &i32
78-
349..350 'k': &mut &i32
79-
353..365 'mut_ref_to_x': &mut &i32
64+
210..236 'if let...rue {}': ()
65+
217..225 'x @ true': &bool
66+
221..225 'true': bool
67+
221..225 'true': bool
68+
228..233 '&true': &bool
69+
229..233 'true': bool
70+
234..236 '{}': ()
71+
246..252 'lambda': |u64, u64, i32| -> i32
72+
255..287 '|a: u6...b; c }': |u64, u64, i32| -> i32
73+
256..257 'a': u64
74+
264..265 'b': u64
75+
267..268 'c': i32
76+
275..287 '{ a + b; c }': i32
77+
277..278 'a': u64
78+
277..282 'a + b': u64
79+
281..282 'b': u64
80+
284..285 'c': i32
81+
298..310 'ref ref_to_x': &&i32
82+
313..314 'x': &i32
83+
324..333 'mut mut_x': &i32
84+
336..337 'x': &i32
85+
347..367 'ref mu...f_to_x': &mut &i32
86+
370..371 'x': &i32
87+
381..382 'k': &mut &i32
88+
385..397 'mut_ref_to_x': &mut &i32
8089
"#]],
8190
);
8291
}

0 commit comments

Comments
 (0)