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