forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathborrowck-let-suggestion-suffixes.rs
61 lines (47 loc) · 2.05 KB
/
borrowck-let-suggestion-suffixes.rs
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
60
61
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
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 does not live long enough
//~| NOTE values in a scope are dropped in the opposite order they are created
let mut v3 = Vec::new(); // statement 5
v3.push(&'x'); // statement 6
//~^ ERROR borrowed value does not live long enough
//~| NOTE temporary value created here
//~| NOTE temporary value only lives until here
//~| NOTE consider using a `let` binding to increase its lifetime
{
let mut v4 = Vec::new(); // (sub) statement 0
v4.push(&'y');
//~^ ERROR borrowed value does not live long enough
//~| NOTE temporary value created here
//~| NOTE temporary value only lives until here
//~| NOTE consider using a `let` binding to increase its lifetime
} // (statement 7)
//~^ NOTE temporary value needs to live until here
let mut v5 = Vec::new(); // statement 8
v5.push(&'z');
//~^ ERROR borrowed value does not live long enough
//~| NOTE temporary value created here
//~| NOTE temporary value only lives until here
//~| NOTE consider using a `let` binding to increase its lifetime
v1.push(&old[0]);
}
//~^ NOTE borrowed value dropped before borrower
//~| NOTE temporary value needs to live until here
//~| NOTE temporary value needs to live until here
fn main() {
f();
}