rust/tests/ui/nll/region-ends-after-if-condition.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
746 B
Rust
Raw Normal View History

2017-10-30 07:28:07 -05:00
// Basic test for liveness constraints: the region (`R1`) that appears
// in the type of `p` includes the points after `&v[0]` up to (but not
// including) the call to `use_x`. The `else` branch is not included.
#![allow(warnings)]
#![feature(rustc_attrs)]
struct MyStruct {
field: String
}
fn foo1() {
2017-10-30 07:28:07 -05:00
let mut my_struct = MyStruct { field: format!("Hello") };
let value = &my_struct.field;
if value.is_empty() {
my_struct.field.push_str("Hello, world!");
}
}
fn foo2() {
let mut my_struct = MyStruct { field: format!("Hello") };
let value = &my_struct.field;
if value.is_empty() {
my_struct.field.push_str("Hello, world!");
2019-05-02 17:34:15 -05:00
//~^ ERROR [E0502]
}
drop(value);
}
fn main() { }