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>
This commit is contained in:
bors[bot] 2021-06-02 18:01:42 +00:00 committed by GitHub
commit 5193728e1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 19 deletions

View File

@ -290,6 +290,10 @@ fn is_non_ref_pat(body: &hir_def::body::Body, pat: PatId) -> bool {
Expr::Literal(Literal::String(..)) => false,
_ => true,
},
Pat::Bind { mode: BindingAnnotation::Mutable, subpat: Some(subpat), .. }
| Pat::Bind { mode: BindingAnnotation::Unannotated, subpat: Some(subpat), .. } => {
is_non_ref_pat(body, *subpat)
}
Pat::Wild | Pat::Bind { .. } | Pat::Ref { .. } | Pat::Box { .. } | Pat::Missing => false,
}
}

View File

@ -20,6 +20,8 @@ fn infer_pattern() {
let h = val;
}
if let x @ true = &true {}
let lambda = |a: u64, b, c: i32| { a + b; c };
let ref ref_to_x = x;
@ -30,7 +32,7 @@ fn infer_pattern() {
"#,
expect![[r#"
8..9 'x': &i32
17..368 '{ ...o_x; }': ()
17..400 '{ ...o_x; }': ()
27..28 'y': &i32
31..32 'x': &i32
42..44 '&z': &i32
@ -59,24 +61,31 @@ fn infer_pattern() {
176..204 '{ ... }': ()
190..191 'h': {unknown}
194..197 'val': {unknown}
214..220 'lambda': |u64, u64, i32| -> i32
223..255 '|a: u6...b; c }': |u64, u64, i32| -> i32
224..225 'a': u64
232..233 'b': u64
235..236 'c': i32
243..255 '{ a + b; c }': i32
245..246 'a': u64
245..250 'a + b': u64
249..250 'b': u64
252..253 'c': i32
266..278 'ref ref_to_x': &&i32
281..282 'x': &i32
292..301 'mut mut_x': &i32
304..305 'x': &i32
315..335 'ref mu...f_to_x': &mut &i32
338..339 'x': &i32
349..350 'k': &mut &i32
353..365 'mut_ref_to_x': &mut &i32
210..236 'if let...rue {}': ()
217..225 'x @ true': &bool
221..225 'true': bool
221..225 'true': bool
228..233 '&true': &bool
229..233 'true': bool
234..236 '{}': ()
246..252 'lambda': |u64, u64, i32| -> i32
255..287 '|a: u6...b; c }': |u64, u64, i32| -> i32
256..257 'a': u64
264..265 'b': u64
267..268 'c': i32
275..287 '{ a + b; c }': i32
277..278 'a': u64
277..282 'a + b': u64
281..282 'b': u64
284..285 'c': i32
298..310 'ref ref_to_x': &&i32
313..314 'x': &i32
324..333 'mut mut_x': &i32
336..337 'x': &i32
347..367 'ref mu...f_to_x': &mut &i32
370..371 'x': &i32
381..382 'k': &mut &i32
385..397 'mut_ref_to_x': &mut &i32
"#]],
);
}