Skip to content

Commit d0fac05

Browse files
committed
Add test for capturing enums
1 parent deeb025 commit d0fac05

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#![feature(capture_disjoint_fields)]
2+
//~^ WARNING the feature `capture_disjoint_fields` is incomplete
3+
#![feature(rustc_attrs)]
4+
5+
enum Info {
6+
Point(i32, i32, String),
7+
Meta(String, Vec<(i32, i32)>)
8+
}
9+
10+
fn multi_variant_enum() {
11+
let point = Info::Point(10, -10, "1".into());
12+
13+
let vec = Vec::new();
14+
let meta = Info::Meta("meta".into(), vec);
15+
16+
let c = #[rustc_capture_analysis]
17+
//~^ ERROR: attributes on expressions are experimental
18+
|| {
19+
if let Info::Point(_, _, str) = point {
20+
//~^ Capturing point[] -> ImmBorrow
21+
//~| Capturing point[(2, 0)] -> ByValue
22+
//~| Min Capture point[] -> ByValue
23+
println!("{}", str);
24+
}
25+
26+
if let Info::Meta(_, v) = meta {
27+
//~^ Capturing meta[] -> ImmBorrow
28+
//~| Capturing meta[(1, 1)] -> ByValue
29+
//~| Min Capture meta[] -> ByValue
30+
println!("{:?}", v);
31+
}
32+
};
33+
34+
c();
35+
}
36+
37+
enum SingleVariant {
38+
Point(i32, i32, String),
39+
}
40+
41+
fn single_variant_enum() {
42+
let point = SingleVariant::Point(10, -10, "1".into());
43+
44+
let c = #[rustc_capture_analysis]
45+
//~^ ERROR: attributes on expressions are experimental
46+
|| {
47+
let SingleVariant::Point(_, _, str) = point;
48+
//~^ Capturing point[(2, 0)] -> ByValue
49+
//~| Min Capture point[(2, 0)] -> ByValue
50+
println!("{}", str);
51+
};
52+
53+
c();
54+
}
55+
56+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
error[E0658]: attributes on expressions are experimental
2+
--> $DIR/capture-enums.rs:16:13
3+
|
4+
LL | let c = #[rustc_capture_analysis]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
8+
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
9+
10+
error[E0658]: attributes on expressions are experimental
11+
--> $DIR/capture-enums.rs:44:13
12+
|
13+
LL | let c = #[rustc_capture_analysis]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
17+
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
18+
19+
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
20+
--> $DIR/capture-enums.rs:1:12
21+
|
22+
LL | #![feature(capture_disjoint_fields)]
23+
| ^^^^^^^^^^^^^^^^^^^^^^^
24+
|
25+
= note: `#[warn(incomplete_features)]` on by default
26+
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
27+
28+
error: Capturing point[] -> ImmBorrow
29+
--> $DIR/capture-enums.rs:19:41
30+
|
31+
LL | if let Info::Point(_, _, str) = point {
32+
| ^^^^^
33+
34+
error: Capturing point[(2, 0)] -> ByValue
35+
--> $DIR/capture-enums.rs:19:41
36+
|
37+
LL | if let Info::Point(_, _, str) = point {
38+
| ^^^^^
39+
40+
error: Capturing meta[] -> ImmBorrow
41+
--> $DIR/capture-enums.rs:26:35
42+
|
43+
LL | if let Info::Meta(_, v) = meta {
44+
| ^^^^
45+
46+
error: Capturing meta[(1, 1)] -> ByValue
47+
--> $DIR/capture-enums.rs:26:35
48+
|
49+
LL | if let Info::Meta(_, v) = meta {
50+
| ^^^^
51+
52+
error: Min Capture point[] -> ByValue
53+
--> $DIR/capture-enums.rs:19:41
54+
|
55+
LL | if let Info::Point(_, _, str) = point {
56+
| ^^^^^
57+
58+
error: Min Capture meta[] -> ByValue
59+
--> $DIR/capture-enums.rs:26:35
60+
|
61+
LL | if let Info::Meta(_, v) = meta {
62+
| ^^^^
63+
64+
error: Capturing point[(2, 0)] -> ByValue
65+
--> $DIR/capture-enums.rs:47:43
66+
|
67+
LL | let SingleVariant::Point(_, _, str) = point;
68+
| ^^^^^
69+
70+
error: Min Capture point[(2, 0)] -> ByValue
71+
--> $DIR/capture-enums.rs:47:43
72+
|
73+
LL | let SingleVariant::Point(_, _, str) = point;
74+
| ^^^^^
75+
76+
error: aborting due to 10 previous errors; 1 warning emitted
77+
78+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)