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