File tree Expand file tree Collapse file tree 2 files changed +21
-14
lines changed
src/test/ui/nll/closure-requirements Expand file tree Collapse file tree 2 files changed +21
-14
lines changed Original file line number Diff line number Diff line change 9
9
// except according to those terms.
10
10
11
11
// Test closure that:
12
- // - captures a variable `y`
13
- // - stores reference to `y` into another, longer-lived spot
12
+ //
13
+ // - captures a variable `y` by reference
14
+ // - stores that reference to `y` into another, longer-lived place (`p`)
15
+ //
16
+ // Both of these are upvars of reference type (the capture of `y` is
17
+ // of type `&'a i32`, the capture of `p` is of type `&mut &'b
18
+ // i32`). The closure thus computes a relationship between `'a` and
19
+ // `'b`. This relationship is propagated to the closure creator,
20
+ // which reports an error.
14
21
15
22
// compile-flags:-Znll -Zborrowck=mir -Zverbose
16
23
Original file line number Diff line number Diff line change 1
1
note: External requirements
2
- --> $DIR/escape-upvar-ref.rs:26 :27
2
+ --> $DIR/escape-upvar-ref.rs:33 :27
3
3
|
4
- 26 | let mut closure = || p = &y;
4
+ 33 | let mut closure = || p = &y;
5
5
| ^^^^^^^^^
6
6
|
7
7
= note: defining type: DefId(0/1:9 ~ escape_upvar_ref[317d]::test[0]::{{closure}}[0]) with closure substs [
@@ -14,26 +14,26 @@ note: External requirements
14
14
= note: where '_#3r: '_#2r
15
15
16
16
note: No external requirements
17
- --> $DIR/escape-upvar-ref.rs:20 :1
17
+ --> $DIR/escape-upvar-ref.rs:27 :1
18
18
|
19
- 20 | / fn test() {
20
- 21 | | let x = 44;
21
- 22 | | let mut p = &x;
22
- 23 | |
19
+ 27 | / fn test() {
20
+ 28 | | let x = 44;
21
+ 29 | | let mut p = &x;
22
+ 30 | |
23
23
... |
24
- 30 | | deref(p);
25
- 31 | | }
24
+ 37 | | deref(p);
25
+ 38 | | }
26
26
| |_^
27
27
|
28
28
= note: defining type: DefId(0/0:3 ~ escape_upvar_ref[317d]::test[0]) with substs []
29
29
30
30
error[E0597]: borrowed value does not live long enough
31
- --> $DIR/escape-upvar-ref.rs:28 :6
31
+ --> $DIR/escape-upvar-ref.rs:35 :6
32
32
|
33
- 25 | let y = 22;
33
+ 32 | let y = 22;
34
34
| - temporary value created here
35
35
...
36
- 28 | } //~ ERROR borrowed value does not live long enough
36
+ 35 | } //~ ERROR borrowed value does not live long enough
37
37
| ^ temporary value dropped here while still borrowed
38
38
|
39
39
= note: consider using a `let` binding to increase its lifetime
You can’t perform that action at this time.
0 commit comments