]> git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/generator-distinct-lifetime.rs
Update upstream source from tag 'upstream/1.27.1+dfsg1'
[rustc.git] / src / test / ui / nll / generator-distinct-lifetime.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(generators, nll)]
12
13 // Test for issue #47189. Here, both `s` and `t` are live for the
14 // generator's lifetime, but within the generator they have distinct
15 // lifetimes. We accept this code -- even though the borrow extends
16 // over a yield -- because the data that is borrowed (`*x`) is not
17 // stored on the stack.
18
19 // compile-pass
20
21 fn foo(x: &mut u32) {
22 move || {
23 let s = &mut *x;
24 yield;
25 *s += 1;
26
27 let t = &mut *x;
28 yield;
29 *t += 1;
30 };
31 }
32
33 fn main() {
34 foo(&mut 0);
35 }