]> git.lizzy.rs Git - rust.git/blob - src/test/ui/generator/yielding-in-match-guards.rs
Merge commit '9809f5d21990d9e24b3e9876ea7da756fd4e9def' into libgccjit-codegen
[rust.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 #![feature(if_let_guard)]
14 #![allow(incomplete_features)]
15
16 async fn f() -> u8 { 1 }
17 async fn foo() -> [bool; 10] { [false; 10] }
18
19 pub async fn g(x: u8) {
20     match x {
21         y if f().await == y => (),
22         _ => (),
23     }
24 }
25
26 // #78366: check the reference to the binding is recorded even if the binding is not autorefed
27
28 async fn h(x: usize) {
29     match x {
30         y if foo().await[y] => (),
31         _ => (),
32     }
33 }
34
35 async fn i(x: u8) {
36     match x {
37         y if f().await == y + 1 => (),
38         _ => (),
39     }
40 }
41
42 async fn j(x: u8) {
43     match x {
44         y if let (1, 42) = (f().await, y) => (),
45         _ => (),
46     }
47 }
48
49 fn main() {
50     let _ = g(10);
51     let _ = h(9);
52     let _ = i(8);
53     let _ = j(7);
54 }