]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/generator-distinct-lifetime.rs
Rollup merge of #103146 - joboet:cleanup_pthread_condvar, r=Mark-Simulacrum
[rust.git] / src / test / ui / nll / generator-distinct-lifetime.rs
1 #![feature(generators)]
2
3 // Test for issue #47189. Here, both `s` and `t` are live for the
4 // generator's lifetime, but within the generator they have distinct
5 // lifetimes. We accept this code -- even though the borrow extends
6 // over a yield -- because the data that is borrowed (`*x`) is not
7 // stored on the stack.
8
9 // check-pass
10
11 fn foo(x: &mut u32) {
12     move || {
13         let s = &mut *x;
14         yield;
15         *s += 1;
16
17         let t = &mut *x;
18         yield;
19         *t += 1;
20     };
21 }
22
23 fn main() {
24     foo(&mut 0);
25 }