]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/borrowck/borrowck-let-suggestion-suffixes.rs
Changed issue number to 36105
[rust.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     //~^ NOTE reference must be valid for the block suffix following statement 2
17
18     let young = ['y'];       // statement 3
19     //~^ NOTE ...but borrowed value is only valid for the block suffix following statement 3
20
21     v2.push(&young[0]);      // statement 4
22     //~^ ERROR `young[..]` does not live long enough
23
24     let mut v3 = Vec::new(); // statement 5
25     //~^ NOTE reference must be valid for the block suffix following statement 5
26
27     v3.push(&'x');           // statement 6
28     //~^ ERROR borrowed value does not live long enough
29     //~| does not live long enough
30     //~| NOTE ...but borrowed value is only valid for the statement
31     //~| HELP consider using a `let` binding to increase its lifetime
32
33     {
34
35         let mut v4 = Vec::new(); // (sub) statement 0
36         //~^ NOTE reference must be valid for the block suffix following statement 0
37
38         v4.push(&'y');
39         //~^ ERROR borrowed value does not live long enough
40         //~| does not live long enough
41         //~| NOTE ...but borrowed value is only valid for the statement
42         //~| HELP consider using a `let` binding to increase its lifetime
43
44     }                       // (statement 7)
45
46     let mut v5 = Vec::new(); // statement 8
47     //~^ NOTE reference must be valid for the block suffix following statement 8
48
49     v5.push(&'z');
50     //~^ ERROR borrowed value does not live long enough
51     //~| does not live long enough
52     //~| NOTE ...but borrowed value is only valid for the statement
53     //~| HELP consider using a `let` binding to increase its lifetime
54
55     v1.push(&old[0]);
56 }
57
58 fn main() {
59     f();
60 }