]> git.proxmox.com Git - rustc.git/blob - src/test/ui/generator/yielding-in-match-guards.rs
Update upstream source from tag 'upstream/1.49.0_beta.4+dfsg1'
[rustc.git] / src / test / ui / generator / yielding-in-match-guards.rs
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
13 async fn f() -> u8 { 1 }
14 async fn foo() -> [bool; 10] { [false; 10] }
15
16 pub async fn g(x: u8) {
17 match x {
18 y if f().await == y => (),
19 _ => (),
20 }
21 }
22
23 // #78366: check the reference to the binding is recorded even if the binding is not autorefed
24
25 async fn h(x: usize) {
26 match x {
27 y if foo().await[y] => (),
28 _ => (),
29 }
30 }
31
32 async fn i(x: u8) {
33 match x {
34 y if f().await == y + 1 => (),
35 _ => (),
36 }
37 }
38
39 fn main() {
40 let _ = g(10);
41 let _ = h(9);
42 let _ = i(8);
43 }