More pattern testcases

This commit is contained in:
Aman Arora 2020-11-05 15:16:24 -05:00
parent fa381600dc
commit be77402ee3
6 changed files with 314 additions and 63 deletions

View File

@ -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() {}

View File

@ -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 <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/destructure_patterns.rs:33: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/destructure_patterns.rs:50: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/destructure_patterns.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 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`.

View File

@ -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();
}

View File

@ -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 <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/slice-pat.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 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`.

View File

@ -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() {}

View File

@ -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 <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/wild_patterns.rs:35: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/wild_patterns.rs:50: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/wild_patterns.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 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`.