]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/return_from_loop.rs
Auto merge of #103600 - compiler-errors:early-binder-nits, r=spastorino
[rust.git] / src / test / ui / nll / return_from_loop.rs
1 // Basic test for liveness constraints: the region (`R1`) that appears
2 // in the type of `p` includes the points after `&v[0]` up to (but not
3 // including) the call to `use_x`. The `else` branch is not included.
4
5 #![allow(warnings)]
6 #![feature(rustc_attrs)]
7
8 struct MyStruct {
9     field: String
10 }
11
12 fn main() {
13 }
14
15 fn nll_fail() {
16     let mut my_struct = MyStruct { field: format!("Hello") };
17
18     let value = &mut my_struct.field;
19     loop {
20         my_struct.field.push_str("Hello, world!");
21         //~^ ERROR [E0499]
22         value.len();
23         return;
24     }
25 }
26
27 fn nll_ok() {
28     let mut my_struct = MyStruct { field: format!("Hello") };
29
30     let value = &mut my_struct.field;
31     loop {
32         my_struct.field.push_str("Hello, world!");
33         return;
34     }
35 }