mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Fix bind patterns always being treated as ref taking patterns
This commit is contained in:
parent
5be653d426
commit
ded4e7cc83
2 changed files with 32 additions and 19 deletions
|
@ -290,6 +290,10 @@ fn is_non_ref_pat(body: &hir_def::body::Body, pat: PatId) -> bool {
|
||||||
Expr::Literal(Literal::String(..)) => false,
|
Expr::Literal(Literal::String(..)) => false,
|
||||||
_ => true,
|
_ => 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,
|
Pat::Wild | Pat::Bind { .. } | Pat::Ref { .. } | Pat::Box { .. } | Pat::Missing => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ fn infer_pattern() {
|
||||||
let h = val;
|
let h = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let x @ true = &true {}
|
||||||
|
|
||||||
let lambda = |a: u64, b, c: i32| { a + b; c };
|
let lambda = |a: u64, b, c: i32| { a + b; c };
|
||||||
|
|
||||||
let ref ref_to_x = x;
|
let ref ref_to_x = x;
|
||||||
|
@ -30,7 +32,7 @@ fn infer_pattern() {
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
8..9 'x': &i32
|
8..9 'x': &i32
|
||||||
17..368 '{ ...o_x; }': ()
|
17..400 '{ ...o_x; }': ()
|
||||||
27..28 'y': &i32
|
27..28 'y': &i32
|
||||||
31..32 'x': &i32
|
31..32 'x': &i32
|
||||||
42..44 '&z': &i32
|
42..44 '&z': &i32
|
||||||
|
@ -59,24 +61,31 @@ fn infer_pattern() {
|
||||||
176..204 '{ ... }': ()
|
176..204 '{ ... }': ()
|
||||||
190..191 'h': {unknown}
|
190..191 'h': {unknown}
|
||||||
194..197 'val': {unknown}
|
194..197 'val': {unknown}
|
||||||
214..220 'lambda': |u64, u64, i32| -> i32
|
210..236 'if let...rue {}': ()
|
||||||
223..255 '|a: u6...b; c }': |u64, u64, i32| -> i32
|
217..225 'x @ true': &bool
|
||||||
224..225 'a': u64
|
221..225 'true': bool
|
||||||
232..233 'b': u64
|
221..225 'true': bool
|
||||||
235..236 'c': i32
|
228..233 '&true': &bool
|
||||||
243..255 '{ a + b; c }': i32
|
229..233 'true': bool
|
||||||
245..246 'a': u64
|
234..236 '{}': ()
|
||||||
245..250 'a + b': u64
|
246..252 'lambda': |u64, u64, i32| -> i32
|
||||||
249..250 'b': u64
|
255..287 '|a: u6...b; c }': |u64, u64, i32| -> i32
|
||||||
252..253 'c': i32
|
256..257 'a': u64
|
||||||
266..278 'ref ref_to_x': &&i32
|
264..265 'b': u64
|
||||||
281..282 'x': &i32
|
267..268 'c': i32
|
||||||
292..301 'mut mut_x': &i32
|
275..287 '{ a + b; c }': i32
|
||||||
304..305 'x': &i32
|
277..278 'a': u64
|
||||||
315..335 'ref mu...f_to_x': &mut &i32
|
277..282 'a + b': u64
|
||||||
338..339 'x': &i32
|
281..282 'b': u64
|
||||||
349..350 'k': &mut &i32
|
284..285 'c': i32
|
||||||
353..365 'mut_ref_to_x': &mut &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
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue