diff --git a/src/test/ui/closures/2229_closure_analysis/capture-enums.rs b/src/test/ui/closures/2229_closure_analysis/capture-enums.rs new file mode 100644 index 0000000000000..175fd79012446 --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/capture-enums.rs @@ -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() {} diff --git a/src/test/ui/closures/2229_closure_analysis/capture-enums.stderr b/src/test/ui/closures/2229_closure_analysis/capture-enums.stderr new file mode 100644 index 0000000000000..76a2de2faf9c8 --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/capture-enums.stderr @@ -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 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 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 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`.