]> git.lizzy.rs Git - rust.git/blob - tests/ui/nll/region-ends-after-if-condition.rs
Auto merge of #101138 - Rejyr:diagnostic-migration-rustc-lint-pt2, r=davidtwco
[rust.git] / tests / ui / nll / region-ends-after-if-condition.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 foo1() {
13     let mut my_struct = MyStruct { field: format!("Hello") };
14
15     let value = &my_struct.field;
16     if value.is_empty() {
17         my_struct.field.push_str("Hello, world!");
18     }
19 }
20
21 fn foo2() {
22     let mut my_struct = MyStruct { field: format!("Hello") };
23
24     let value = &my_struct.field;
25     if value.is_empty() {
26         my_struct.field.push_str("Hello, world!");
27         //~^ ERROR [E0502]
28     }
29     drop(value);
30 }
31
32 fn main() { }