Skip to content

Commit 7be157a

Browse files
test: cover current if let closure capture behavior
1 parent 562dee4 commit 7be157a

2 files changed

Lines changed: 144 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//@ edition:2021
2+
3+
#![feature(rustc_attrs)]
4+
#![feature(stmt_expr_attributes)]
5+
#![allow(irrefutable_let_patterns)]
6+
7+
enum SingleVariant {
8+
Pair(i32, String),
9+
}
10+
11+
fn if_let_closure() {
12+
let variant = SingleVariant::Pair(1, "hello".into());
13+
14+
let c = #[rustc_capture_analysis]
15+
|| {
16+
//~^ ERROR First Pass analysis includes:
17+
//~| ERROR Min Capture analysis includes:
18+
if let SingleVariant::Pair(ref n, s) = variant {
19+
//~^ NOTE: Capturing variant[] -> Immutable
20+
//~| NOTE: Capturing variant[(0, 0)] -> Immutable
21+
//~| NOTE: Capturing variant[(1, 0)] -> ByValue
22+
//~| NOTE: Min Capture variant[] -> ByValue
23+
let _ = (n, s);
24+
}
25+
};
26+
27+
c();
28+
}
29+
30+
fn match_closure() {
31+
let variant = SingleVariant::Pair(1, "hello".into());
32+
33+
let c = #[rustc_capture_analysis]
34+
|| {
35+
//~^ ERROR First Pass analysis includes:
36+
//~| ERROR Min Capture analysis includes:
37+
match variant {
38+
//~^ NOTE: Capturing variant[(0, 0)] -> Immutable
39+
//~| NOTE: Capturing variant[(1, 0)] -> ByValue
40+
//~| NOTE: Min Capture variant[(0, 0)] -> Immutable
41+
//~| NOTE: Min Capture variant[(1, 0)] -> ByValue
42+
SingleVariant::Pair(ref n, s) => {
43+
let _ = (n, s);
44+
}
45+
}
46+
};
47+
48+
c();
49+
}
50+
51+
fn main() {
52+
if_let_closure();
53+
match_closure();
54+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
error: First Pass analysis includes:
2+
--> $DIR/if-let-patterns-capture-analysis.rs:15:5
3+
|
4+
LL | / || {
5+
LL | |
6+
LL | |
7+
LL | | if let SingleVariant::Pair(ref n, s) = variant {
8+
... |
9+
LL | | };
10+
| |_____^
11+
|
12+
note: Capturing variant[] -> Immutable
13+
--> $DIR/if-let-patterns-capture-analysis.rs:18:48
14+
|
15+
LL | if let SingleVariant::Pair(ref n, s) = variant {
16+
| ^^^^^^^
17+
note: Capturing variant[(0, 0)] -> Immutable
18+
--> $DIR/if-let-patterns-capture-analysis.rs:18:48
19+
|
20+
LL | if let SingleVariant::Pair(ref n, s) = variant {
21+
| ^^^^^^^
22+
note: Capturing variant[(1, 0)] -> ByValue
23+
--> $DIR/if-let-patterns-capture-analysis.rs:18:48
24+
|
25+
LL | if let SingleVariant::Pair(ref n, s) = variant {
26+
| ^^^^^^^
27+
28+
error: Min Capture analysis includes:
29+
--> $DIR/if-let-patterns-capture-analysis.rs:15:5
30+
|
31+
LL | / || {
32+
LL | |
33+
LL | |
34+
LL | | if let SingleVariant::Pair(ref n, s) = variant {
35+
... |
36+
LL | | };
37+
| |_____^
38+
|
39+
note: Min Capture variant[] -> ByValue
40+
--> $DIR/if-let-patterns-capture-analysis.rs:18:48
41+
|
42+
LL | if let SingleVariant::Pair(ref n, s) = variant {
43+
| ^^^^^^^
44+
45+
error: First Pass analysis includes:
46+
--> $DIR/if-let-patterns-capture-analysis.rs:34:5
47+
|
48+
LL | / || {
49+
LL | |
50+
LL | |
51+
LL | | match variant {
52+
... |
53+
LL | | };
54+
| |_____^
55+
|
56+
note: Capturing variant[(0, 0)] -> Immutable
57+
--> $DIR/if-let-patterns-capture-analysis.rs:37:15
58+
|
59+
LL | match variant {
60+
| ^^^^^^^
61+
note: Capturing variant[(1, 0)] -> ByValue
62+
--> $DIR/if-let-patterns-capture-analysis.rs:37:15
63+
|
64+
LL | match variant {
65+
| ^^^^^^^
66+
67+
error: Min Capture analysis includes:
68+
--> $DIR/if-let-patterns-capture-analysis.rs:34:5
69+
|
70+
LL | / || {
71+
LL | |
72+
LL | |
73+
LL | | match variant {
74+
... |
75+
LL | | };
76+
| |_____^
77+
|
78+
note: Min Capture variant[(0, 0)] -> Immutable
79+
--> $DIR/if-let-patterns-capture-analysis.rs:37:15
80+
|
81+
LL | match variant {
82+
| ^^^^^^^
83+
note: Min Capture variant[(1, 0)] -> ByValue
84+
--> $DIR/if-let-patterns-capture-analysis.rs:37:15
85+
|
86+
LL | match variant {
87+
| ^^^^^^^
88+
89+
error: aborting due to 4 previous errors
90+

0 commit comments

Comments
 (0)