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