8000 RFC-2229: Implement Precise Capture Analysis by arora-aman · Pull Request #78801 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

RFC-2229: Implement Precise Capture Analysis #78801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for capturing enums
  • Loading branch information
arora-aman committed Nov 11, 2020
commit d0fac05d8f0920d0aaa81dc4832334a49e7dbff8
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