Skip to content

Commit

Permalink
Add test for capturing enums
Browse files Browse the repository at this point in the history
  • Loading branch information
arora-aman committed Nov 11, 2020
1 parent deeb025 commit d0fac05
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/test/ui/closures/2229_closure_analysis/capture-enums.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#![feature(capture_disjoint_fields)]
//~^ WARNING the feature `capture_disjoint_fields` is incomplete
#![feature(rustc_attrs)]

enum Info {
Point(i32, i32, String),
Meta(String, Vec<(i32, i32)>)
}

fn multi_variant_enum() {
let point = Info::Point(10, -10, "1".into());

let vec = Vec::new();
let meta = Info::Meta("meta".into(), vec);

let c = #[rustc_capture_analysis]
//~^ ERROR: attributes on expressions are experimental
|| {
if let Info::Point(_, _, str) = point {
//~^ Capturing point[] -> ImmBorrow
//~| Capturing point[(2, 0)] -> ByValue
//~| Min Capture point[] -> ByValue
println!("{}", str);
}

if let Info::Meta(_, v) = meta {
//~^ Capturing meta[] -> ImmBorrow
//~| Capturing meta[(1, 1)] -> ByValue
//~| Min Capture meta[] -> ByValue
println!("{:?}", v);
}
};

c();
}

enum SingleVariant {
Point(i32, i32, String),
}

fn single_variant_enum() {
let point = SingleVariant::Point(10, -10, "1".into());

let c = #[rustc_capture_analysis]
//~^ ERROR: attributes on expressions are experimental
|| {
let SingleVariant::Point(_, _, str) = point;
//~^ Capturing point[(2, 0)] -> ByValue
//~| Min Capture point[(2, 0)] -> ByValue
println!("{}", str);
};

c();
}

fn main() {}
78 changes: 78 additions & 0 deletions src/test/ui/closures/2229_closure_analysis/capture-enums.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
error[E0658]: attributes on expressions are experimental
--> $DIR/capture-enums.rs:16:13
|
LL | let c = #[rustc_capture_analysis]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable

error[E0658]: attributes on expressions are experimental
--> $DIR/capture-enums.rs:44:13
|
LL | let c = #[rustc_capture_analysis]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable

warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/capture-enums.rs:1:12
|
LL | #![feature(capture_disjoint_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information

error: Capturing point[] -> ImmBorrow
--> $DIR/capture-enums.rs:19:41
|
LL | if let Info::Point(_, _, str) = point {
| ^^^^^

error: Capturing point[(2, 0)] -> ByValue
--> $DIR/capture-enums.rs:19:41
|
LL | if let Info::Point(_, _, str) = point {
| ^^^^^

error: Capturing meta[] -> ImmBorrow
--> $DIR/capture-enums.rs:26:35
|
LL | if let Info::Meta(_, v) = meta {
| ^^^^

error: Capturing meta[(1, 1)] -> ByValue
--> $DIR/capture-enums.rs:26:35
|
LL | if let Info::Meta(_, v) = meta {
| ^^^^

error: Min Capture point[] -> ByValue
--> $DIR/capture-enums.rs:19:41
|
LL | if let Info::Point(_, _, str) = point {
| ^^^^^

error: Min Capture meta[] -> ByValue
--> $DIR/capture-enums.rs:26:35
|
LL | if let Info::Meta(_, v) = meta {
| ^^^^

error: Capturing point[(2, 0)] -> ByValue
--> $DIR/capture-enums.rs:47:43
|
LL | let SingleVariant::Point(_, _, str) = point;
| ^^^^^

error: Min Capture point[(2, 0)] -> ByValue
--> $DIR/capture-enums.rs:47:43
|
LL | let SingleVariant::Point(_, _, str) = point;
| ^^^^^

error: aborting due to 10 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0658`.

0 comments on commit d0fac05

Please sign in to comment.