]> git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/return_from_loop.rs
Update upstream source from tag 'upstream/1.31.0_beta.4+dfsg1'
[rustc.git] / src / test / ui / nll / return_from_loop.rs
1 // Copyright 2012-2016 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 // Basic test for liveness constraints: the region (`R1`) that appears
12 // in the type of `p` includes the points after `&v[0]` up to (but not
13 // including) the call to `use_x`. The `else` branch is not included.
14
15 // compile-flags:-Zborrowck=compare
16
17 #![allow(warnings)]
18 #![feature(rustc_attrs)]
19
20 struct MyStruct {
21 field: String
22 }
23
24 fn main() {
25 }
26
27 fn nll_fail() {
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 //~^ ERROR (Ast) [E0499]
34 //~| ERROR (Mir) [E0499]
35 value.len();
36 return;
37 }
38 }
39
40 fn nll_ok() {
41 let mut my_struct = MyStruct { field: format!("Hello") };
42
43 let value = &mut my_struct.field;
44 loop {
45 my_struct.field.push_str("Hello, world!");
46 //~^ ERROR (Ast) [E0499]
47 return;
48 }
49 }