blob: 6240f103c99b062a9b60bce70c161ef94efe65a8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
fn id<T>(x: T) -> T { x }
fn f() {
let old = ['o']; // statement 0
let mut v1 = Vec::new(); // statement 1
let mut v2 = Vec::new(); // statement 2
{
let young = ['y']; // statement 3
v2.push(&young[0]); // statement 4
//~^ ERROR `young[_]` does not live long enough
//~| NOTE borrowed value does not live long enough
} //~ NOTE `young[_]` dropped here while still borrowed
let mut v3 = Vec::new(); // statement 5
v3.push(&id('x')); // statement 6
//~^ ERROR temporary value dropped while borrowed
//~| NOTE creates a temporary which is freed while still in use
//~| NOTE temporary value is freed at the end of this statement
//~| HELP consider using a `let` binding to create a longer lived value
{
let mut v4 = Vec::new(); // (sub) statement 0
v4.push(&id('y'));
//~^ ERROR temporary value dropped while borrowed
//~| NOTE creates a temporary which is freed while still in use
//~| NOTE temporary value is freed at the end of this statement
//~| NOTE consider using a `let` binding to create a longer lived value
v4.use_ref();
//~^ NOTE borrow later used here
} // (statement 7)
let mut v5 = Vec::new(); // statement 8
v5.push(&id('z'));
//~^ ERROR temporary value dropped while borrowed
//~| NOTE creates a temporary which is freed while still in use
//~| NOTE temporary value is freed at the end of this statement
//~| HELP consider using a `let` binding to create a longer lived value
v1.push(&old[0]);
(v1, v2, v3, /* v4 is above. */ v5).use_ref();
//~^ NOTE borrow later used here
//~| NOTE borrow later used here
//~| NOTE borrow later used here
}
fn main() {
f();
}
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }
|