From be77402ee3ca6a4cab16b45c8c35baa13a9d5a05 Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Thu, 5 Nov 2020 15:16:24 -0500 Subject: [PATCH] More pattern testcases --- .../destructure_patterns.rs | 66 +++++++++++ .../destructure_patterns.stderr | 111 ++++++++++++++++++ .../2229_closure_analysis/slice-pat.rs | 30 ----- .../2229_closure_analysis/slice-pat.stderr | 33 ------ .../2229_closure_analysis/wild_patterns.rs | 62 ++++++++++ .../wild_patterns.stderr | 75 ++++++++++++ 6 files changed, 314 insertions(+), 63 deletions(-) create mode 100644 src/test/ui/closures/2229_closure_analysis/destructure_patterns.rs create mode 100644 src/test/ui/closures/2229_closure_analysis/destructure_patterns.stderr delete mode 100644 src/test/ui/closures/2229_closure_analysis/slice-pat.rs delete mode 100644 src/test/ui/closures/2229_closure_analysis/slice-pat.stderr create mode 100644 src/test/ui/closures/2229_closure_analysis/wild_patterns.rs create mode 100644 src/test/ui/closures/2229_closure_analysis/wild_patterns.stderr diff --git a/src/test/ui/closures/2229_closure_analysis/destructure_patterns.rs b/src/test/ui/closures/2229_closure_analysis/destructure_patterns.rs new file mode 100644 index 00000000000..36f258f950f --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/destructure_patterns.rs @@ -0,0 +1,66 @@ +#![feature(capture_disjoint_fields)] +//~^ WARNING the feature `capture_disjoint_fields` is incomplete +#![feature(rustc_attrs)] + +// Test to ensure Index projections are handled properly during capture analysis +// The array should be moved in entirety, even though only some elements are used. +fn arrays() { + let arr: [String; 5] = [format!("A"), format!("B"), format!("C"), format!("D"), format!("E")]; + + let c = #[rustc_capture_analysis] + //~^ ERROR: attributes on expressions are experimental + || { + let [a, b, .., e] = arr; + //~^ ERROR: Capturing arr[Index] -> ByValue + //~^^ ERROR: Min Capture arr[] -> ByValue + assert_eq!(a, "A"); + assert_eq!(b, "B"); + assert_eq!(e, "E"); + }; + + c(); +} + +struct Point { + x: i32, + y: i32, + id: String, +} + +fn structs() { + let mut p = Point { x: 10, y: 10, id: String::new() }; + + let c = #[rustc_capture_analysis] + //~^ ERROR: attributes on expressions are experimental + || { + let Point { x: ref mut x, y: _, id: moved_id } = p; + //~^ ERROR: Capturing p[(0, 0)] -> MutBorrow + //~^^ ERROR: Capturing p[(2, 0)] -> ByValue + //~^^^ ERROR: Min Capture p[(0, 0)] -> MutBorrow + //~^^^^ ERROR: Min Capture p[(2, 0)] -> ByValue + + println!("{}, {}", x, moved_id); + }; + c(); +} + +fn tuples() { + let mut t = (10, String::new(), (String::new(), 42)); + + let c = #[rustc_capture_analysis] + //~^ ERROR: attributes on expressions are experimental + || { + let (ref mut x, ref ref_str, (moved_s, _)) = t; + //~^ ERROR: Capturing t[(0, 0)] -> MutBorrow + //~^^ ERROR: Capturing t[(1, 0)] -> ImmBorrow + //~^^^ ERROR: Capturing t[(2, 0),(0, 0)] -> ByValue + //~^^^^ ERROR: Min Capture t[(0, 0)] -> MutBorrow + //~^^^^^ ERROR: Min Capture t[(1, 0)] -> ImmBorrow + //~^^^^^^ ERROR: Min Capture t[(2, 0),(0, 0)] -> ByValue + + println!("{}, {} {}", x, ref_str, moved_s); + }; + c(); +} + +fn main() {} diff --git a/src/test/ui/closures/2229_closure_analysis/destructure_patterns.stderr b/src/test/ui/closures/2229_closure_analysis/destructure_patterns.stderr new file mode 100644 index 00000000000..388cfd3da92 --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/destructure_patterns.stderr @@ -0,0 +1,111 @@ +error[E0658]: attributes on expressions are experimental + --> $DIR/destructure_patterns.rs:10: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/destructure_patterns.rs:33: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/destructure_patterns.rs:50: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/destructure_patterns.rs:1:12 + | +LL | #![feature(capture_disjoint_fields)] + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #53488 for more information + +error: Capturing arr[Index] -> ByValue + --> $DIR/destructure_patterns.rs:13:29 + | +LL | let [a, b, .., e] = arr; + | ^^^ + +error: Min Capture arr[] -> ByValue + --> $DIR/destructure_patterns.rs:13:29 + | +LL | let [a, b, .., e] = arr; + | ^^^ + +error: Capturing p[(0, 0)] -> MutBorrow + --> $DIR/destructure_patterns.rs:36:58 + | +LL | let Point { x: ref mut x, y: _, id: moved_id } = p; + | ^ + +error: Capturing p[(2, 0)] -> ByValue + --> $DIR/destructure_patterns.rs:36:58 + | +LL | let Point { x: ref mut x, y: _, id: moved_id } = p; + | ^ + +error: Min Capture p[(0, 0)] -> MutBorrow + --> $DIR/destructure_patterns.rs:36:58 + | +LL | let Point { x: ref mut x, y: _, id: moved_id } = p; + | ^ + +error: Min Capture p[(2, 0)] -> ByValue + --> $DIR/destructure_patterns.rs:36:58 + | +LL | let Point { x: ref mut x, y: _, id: moved_id } = p; + | ^ + +error: Capturing t[(0, 0)] -> MutBorrow + --> $DIR/destructure_patterns.rs:53:54 + | +LL | let (ref mut x, ref ref_str, (moved_s, _)) = t; + | ^ + +error: Capturing t[(1, 0)] -> ImmBorrow + --> $DIR/destructure_patterns.rs:53:54 + | +LL | let (ref mut x, ref ref_str, (moved_s, _)) = t; + | ^ + +error: Capturing t[(2, 0),(0, 0)] -> ByValue + --> $DIR/destructure_patterns.rs:53:54 + | +LL | let (ref mut x, ref ref_str, (moved_s, _)) = t; + | ^ + +error: Min Capture t[(0, 0)] -> MutBorrow + --> $DIR/destructure_patterns.rs:53:54 + | +LL | let (ref mut x, ref ref_str, (moved_s, _)) = t; + | ^ + +error: Min Capture t[(1, 0)] -> ImmBorrow + --> $DIR/destructure_patterns.rs:53:54 + | +LL | let (ref mut x, ref ref_str, (moved_s, _)) = t; + | ^ + +error: Min Capture t[(2, 0),(0, 0)] -> ByValue + --> $DIR/destructure_patterns.rs:53:54 + | +LL | let (ref mut x, ref ref_str, (moved_s, _)) = t; + | ^ + +error: aborting due to 15 previous errors; 1 warning emitted + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/slice-pat.rs b/src/test/ui/closures/2229_closure_analysis/slice-pat.rs deleted file mode 100644 index 4e30194b17e..00000000000 --- a/src/test/ui/closures/2229_closure_analysis/slice-pat.rs +++ /dev/null @@ -1,30 +0,0 @@ -#![feature(capture_disjoint_fields)] -//~^ WARNING the feature `capture_disjoint_fields` is incomplete -#![feature(rustc_attrs)] - -// Test to ensure Index projections are handled properly during capture analysis -// -// The array should be moved in entirety, even though only some elements are used. - -fn main() { - let arr : [String; 5] = [ - format!("A"), - format!("B"), - format!("C"), - format!("D"), - format!("E") - ]; - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - || { - let [a, b, .., e] = arr; - //~^ ERROR: Capturing arr[Index] -> ByValue - //~^^ ERROR: Min Capture arr[] -> ByValue - assert_eq!(a, "A"); - assert_eq!(b, "B"); - assert_eq!(e, "E"); - }; - - c(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/slice-pat.stderr b/src/test/ui/closures/2229_closure_analysis/slice-pat.stderr deleted file mode 100644 index 2547322a8ab..00000000000 --- a/src/test/ui/closures/2229_closure_analysis/slice-pat.stderr +++ /dev/null @@ -1,33 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/slice-pat.rs:18: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/slice-pat.rs:1:12 - | -LL | #![feature(capture_disjoint_fields)] - | ^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #53488 for more information - -error: Capturing arr[Index] -> ByValue - --> $DIR/slice-pat.rs:21:33 - | -LL | let [a, b, .., e] = arr; - | ^^^ - -error: Min Capture arr[] -> ByValue - --> $DIR/slice-pat.rs:21:33 - | -LL | let [a, b, .., e] = arr; - | ^^^ - -error: aborting due to 3 previous errors; 1 warning emitted - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/wild_patterns.rs b/src/test/ui/closures/2229_closure_analysis/wild_patterns.rs new file mode 100644 index 00000000000..d17af7cc79a --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/wild_patterns.rs @@ -0,0 +1,62 @@ +#![feature(capture_disjoint_fields)] +//~^ WARNING the feature `capture_disjoint_fields` is incomplete +#![feature(rustc_attrs)] + +// Test to ensure that we can handle cases where +// let statements create no bindings are intialized +// using a Place expression +// +// Note: Currently when feature `capture_disjoint_fields` is enabled +// we can't handle such cases. So the test so the test + +struct Point { + x: i32, + y: i32, +} + +fn wild_struct() { + let p = Point { x: 10, y: 20 }; + + let c = #[rustc_capture_analysis] + //~^ ERROR: attributes on expressions are experimental + || { + // FIXME(arora-aman): Change `_x` to `_` + let Point { x: _x, y: _ } = p; + //~^ ERROR: Capturing p[(0, 0)] -> ImmBorrow + //~^^ ERROR: Min Capture p[(0, 0)] -> ImmBorrow + }; + + c(); +} + +fn wild_tuple() { + let t = (String::new(), 10); + + let c = #[rustc_capture_analysis] + //~^ ERROR: attributes on expressions are experimental + || { + // FIXME(arora-aman): Change `_x` to `_` + let (_x, _) = t; + //~^ ERROR: Capturing t[(0, 0)] -> ByValue + //~^^ ERROR: Min Capture t[(0, 0)] -> ByValue + }; + + c(); +} + +fn wild_arr() { + let arr = [String::new(), String::new()]; + + let c = #[rustc_capture_analysis] + //~^ ERROR: attributes on expressions are experimental + || { + // FIXME(arora-aman): Change `_x` to `_` + let [_x, _] = arr; + //~^ ERROR: Capturing arr[Index] -> ByValue + //~^^ ERROR: Min Capture arr[] -> ByValue + }; + + c(); +} + +fn main() {} diff --git a/src/test/ui/closures/2229_closure_analysis/wild_patterns.stderr b/src/test/ui/closures/2229_closure_analysis/wild_patterns.stderr new file mode 100644 index 00000000000..621c8aeb790 --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/wild_patterns.stderr @@ -0,0 +1,75 @@ +error[E0658]: attributes on expressions are experimental + --> $DIR/wild_patterns.rs:20: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/wild_patterns.rs:35: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/wild_patterns.rs:50: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/wild_patterns.rs:1:12 + | +LL | #![feature(capture_disjoint_fields)] + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #53488 for more information + +error: Capturing p[(0, 0)] -> ImmBorrow + --> $DIR/wild_patterns.rs:24:37 + | +LL | let Point { x: _x, y: _ } = p; + | ^ + +error: Min Capture p[(0, 0)] -> ImmBorrow + --> $DIR/wild_patterns.rs:24:37 + | +LL | let Point { x: _x, y: _ } = p; + | ^ + +error: Capturing t[(0, 0)] -> ByValue + --> $DIR/wild_patterns.rs:39:23 + | +LL | let (_x, _) = t; + | ^ + +error: Min Capture t[(0, 0)] -> ByValue + --> $DIR/wild_patterns.rs:39:23 + | +LL | let (_x, _) = t; + | ^ + +error: Capturing arr[Index] -> ByValue + --> $DIR/wild_patterns.rs:54:23 + | +LL | let [_x, _] = arr; + | ^^^ + +error: Min Capture arr[] -> ByValue + --> $DIR/wild_patterns.rs:54:23 + | +LL | let [_x, _] = arr; + | ^^^ + +error: aborting due to 9 previous errors; 1 warning emitted + +For more information about this error, try `rustc --explain E0658`. -- 2.44.0