]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/borrowck/borrowck-let-suggestion-suffixes.rs
New upstream version 1.13.0+dfsg1
[rustc.git] / src / test / compile-fail / borrowck / borrowck-let-suggestion-suffixes.rs
1 // Copyright 2015 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 fn f() {
12 let old = ['o']; // statement 0
13 let mut v1 = Vec::new(); // statement 1
14
15 let mut v2 = Vec::new(); // statement 2
16
17 let young = ['y']; // statement 3
18
19 v2.push(&young[0]); // statement 4
20 //~^ ERROR `young[..]` does not live long enough
21 //~| NOTE does not live long enough
22 //~| NOTE values in a scope are dropped in the opposite order they are created
23
24 let mut v3 = Vec::new(); // statement 5
25
26 v3.push(&'x'); // statement 6
27 //~^ ERROR borrowed value does not live long enough
28 //~| NOTE temporary value created here
29 //~| NOTE temporary value only lives until here
30 //~| NOTE consider using a `let` binding to increase its lifetime
31
32 {
33
34 let mut v4 = Vec::new(); // (sub) statement 0
35
36 v4.push(&'y');
37 //~^ ERROR borrowed value does not live long enough
38 //~| NOTE temporary value created here
39 //~| NOTE temporary value only lives until here
40 //~| NOTE consider using a `let` binding to increase its lifetime
41
42 } // (statement 7)
43 //~^ NOTE temporary value needs to live until here
44
45 let mut v5 = Vec::new(); // statement 8
46
47 v5.push(&'z');
48 //~^ ERROR borrowed value does not live long enough
49 //~| NOTE temporary value created here
50 //~| NOTE temporary value only lives until here
51 //~| NOTE consider using a `let` binding to increase its lifetime
52
53 v1.push(&old[0]);
54 }
55 //~^ NOTE borrowed value dropped before borrower
56 //~| NOTE temporary value needs to live until here
57 //~| NOTE temporary value needs to live until here
58
59 fn main() {
60 f();
61 }