]> git.proxmox.com Git - rustc.git/blame - src/test/ui/generator/yielding-in-match-guards.rs
New upstream version 1.56.0~beta.4+dfsg1
[rustc.git] / src / test / ui / generator / yielding-in-match-guards.rs
CommitLineData
29967ef6
XL
1// build-pass
2// edition:2018
3
4// This test is derived from
5// https://github.com/rust-lang/rust/issues/72651#issuecomment-668720468
6
7// This test demonstrates that, in `async fn g()`,
8// indeed a temporary borrow `y` from `x` is live
9// while `f().await` is being evaluated.
10// Thus, `&'_ u8` should be included in type signature
11// of the underlying generator.
12
fc512014 13#![feature(if_let_guard)]
fc512014 14
29967ef6
XL
15async fn f() -> u8 { 1 }
16async fn foo() -> [bool; 10] { [false; 10] }
17
18pub async fn g(x: u8) {
19 match x {
20 y if f().await == y => (),
21 _ => (),
22 }
23}
24
25// #78366: check the reference to the binding is recorded even if the binding is not autorefed
26
27async fn h(x: usize) {
28 match x {
29 y if foo().await[y] => (),
30 _ => (),
31 }
32}
33
34async fn i(x: u8) {
35 match x {
36 y if f().await == y + 1 => (),
37 _ => (),
38 }
39}
40
fc512014
XL
41async fn j(x: u8) {
42 match x {
43 y if let (1, 42) = (f().await, y) => (),
44 _ => (),
45 }
46}
47
29967ef6
XL
48fn main() {
49 let _ = g(10);
50 let _ = h(9);
51 let _ = i(8);
fc512014 52 let _ = j(7);
29967ef6 53}