Skip to content

Commit a584eeb

Browse files
committed
More pattern testcases
1 parent b4851fc commit a584eeb

File tree

6 files changed

+314
-63
lines changed

6 files changed

+314
-63
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#![feature(capture_disjoint_fields)]
2+
//~^ WARNING the feature `capture_disjoint_fields` is incomplete
3+
#![feature(rustc_attrs)]
4+
5+
// Test to ensure Index projections are handled properly during capture analysis
6+
// The array should be moved in entirety, even though only some elements are used.
7+
fn arrays() {
8+
let arr: [String; 5] = [format!("A"), format!("B"), format!("C"), format!("D"), format!("E")];
9+
10+
let c = #[rustc_capture_analysis]
11+
//~^ ERROR: attributes on expressions are experimental
12+
|| {
13+
let [a, b, .., e] = arr;
14+
//~^ ERROR: Capturing arr[Index] -> ByValue
15+
//~^^ ERROR: Min Capture arr[] -> ByValue
16+
assert_eq!(a, "A");
17+
assert_eq!(b, "B");
18+
assert_eq!(e, "E");
19+
};
20+
21+
c();
22+
}
23+
24+
struct Point {
25+
x: i32,
26+
y: i32,
27+
id: String,
28+
}
29+
30+
fn structs() {
31+
let mut p = Point { x: 10, y: 10, id: String::new() };
32+
33+
let c = #[rustc_capture_analysis]
34+
//~^ ERROR: attributes on expressions are experimental
35+
|| {
36+
let Point { x: ref mut x, y: _, id: moved_id } = p;
37+
//~^ ERROR: Capturing p[(0, 0)] -> MutBorrow
38+
//~^^ ERROR: Capturing p[(2, 0)] -> ByValue
39+
//~^^^ ERROR: Min Capture p[(0, 0)] -> MutBorrow
40+
//~^^^^ ERROR: Min Capture p[(2, 0)] -> ByValue
41+
42+
println!("{}, {}", x, moved_id);
43+
};
44+
c();
45+
}
46+
47+
fn tuples() {
48+
let mut t = (10, String::new(), (String::new(), 42));
49+
50+
let c = #[rustc_capture_analysis]
51+
//~^ ERROR: attributes on expressions are experimental
52+
|| {
53+
let (ref mut x, ref ref_str, (moved_s, _)) = t;
54+
//~^ ERROR: Capturing t[(0, 0)] -> MutBorrow
55+
//~^^ ERROR: Capturing t[(1, 0)] -> ImmBorrow
56+
//~^^^ ERROR: Capturing t[(2, 0),(0, 0)] -> ByValue
57+
//~^^^^ ERROR: Min Capture t[(0, 0)] -> MutBorrow
58+
//~^^^^^ ERROR: Min Capture t[(1, 0)] -> ImmBorrow
59+
//~^^^^^^ ERROR: Min Capture t[(2, 0),(0, 0)] -> ByValue
60+
61+
println!("{}, {} {}", x, ref_str, moved_s);
62+
};
63+
c();
64+
}
65+
66+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
error[E0658]: attributes on expressions are experimental
2+
--> $DIR/destructure_patterns.rs:10:13
3+
|
4+
LL | let c = #[rustc_capture_analysis]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
8+
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
9+
10+
error[E0658]: attributes on expressions are experimental
11+
--> $DIR/destructure_patterns.rs:33:13
12+
|
13+
LL | let c = #[rustc_capture_analysis]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
17+
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
18+
19+
error[E0658]: attributes on expressions are experimental
20+
--> $DIR/destructure_patterns.rs:50:13
21+
|
22+
LL | let c = #[rustc_capture_analysis]
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
24+
|
25+
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
26+
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
27+
28+
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
29+
--> $DIR/destructure_patterns.rs:1:12
30+
|
31+
LL | #![feature(capture_disjoint_fields)]
32+
| ^^^^^^^^^^^^^^^^^^^^^^^
33+
|
34+
= note: `#[warn(incomplete_features)]` on by default
35+
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
36+
37+
error: Capturing arr[Index] -> ByValue
38+
--> $DIR/destructure_patterns.rs:13:29
39+
|
40+
LL | let [a, b, .., e] = arr;
41+
| ^^^
42+
43+
error: Min Capture arr[] -> ByValue
44+
--> $DIR/destructure_patterns.rs:13:29
45+
|
46+
LL | let [a, b, .., e] = arr;
47+
| ^^^
48+
49+
error: Capturing p[(0, 0)] -> MutBorrow
50+
--> $DIR/destructure_patterns.rs:36:58
51+
|
52+
LL | let Point { x: ref mut x, y: _, id: moved_id } = p;
53+
| ^
54+
55+
error: Capturing p[(2, 0)] -> ByValue
56+
--> $DIR/destructure_patterns.rs:36:58
57+
|
58+
LL | let Point { x: ref mut x, y: _, id: moved_id } = p;
59+
| ^
60+
61+
error: Min Capture p[(0, 0)] -> MutBorrow
62+
--> $DIR/destructure_patterns.rs:36:58
63+
|
64+
LL | let Point { x: ref mut x, y: _, id: moved_id } = p;
65+
| ^
66+
67+
error: Min Capture p[(2, 0)] -> ByValue
68+
--> $DIR/destructure_patterns.rs:36:58
69+
|
70+
LL | let Point { x: ref mut x, y: _, id: moved_id } = p;
71+
| ^
72+
73+
error: Capturing t[(0, 0)] -> MutBorrow
74+
--> $DIR/destructure_patterns.rs:53:54
75+
|
76+
LL | let (ref mut x, ref ref_str, (moved_s, _)) = t;
77+
| ^
78+
79+
error: Capturing t[(1, 0)] -> ImmBorrow
80+
--> $DIR/destructure_patterns.rs:53:54
81+
|
82+
LL | let (ref mut x, ref ref_str, (moved_s, _)) = t;
83+
| ^
84+
85+
error: Capturing t[(2, 0),(0, 0)] -> ByValue
86+
--> $DIR/destructure_patterns.rs:53:54
87+
|
88+
LL | let (ref mut x, ref ref_str, (moved_s, _)) = t;
89+
| ^
90+
91+
error: Min Capture t[(0, 0)] -> MutBorrow
92+
--> $DIR/destructure_patterns.rs:53:54
93+
|
94+
LL | let (ref mut x, ref ref_str, (moved_s, _)) = t;
95+
| ^
96+
97+
error: Min Capture t[(1, 0)] -> ImmBorrow
98+
--> $DIR/destructure_patterns.rs:53:54
99+
|
100+
LL | let (ref mut x, ref ref_str, (moved_s, _)) = t;
101+
| ^
102+
103+
error: Min Capture t[(2, 0),(0, 0)] -> ByValue
104+
--> $DIR/destructure_patterns.rs:53:54
105+
|
106+
LL | let (ref mut x, ref ref_str, (moved_s, _)) = t;
107+
| ^
108+
109+
error: aborting due to 15 previous errors; 1 warning emitted
110+
111+
For more information about this error, try `rustc --explain E0658`.

src/test/ui/closures/2229_closure_analysis/slice-pat.rs

-30
This file was deleted.

src/test/ui/closures/2229_closure_analysis/slice-pat.stderr

-33
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#![feature(capture_disjoint_fields)]
2+
//~^ WARNING the feature `capture_disjoint_fields` is incomplete
3+
#![feature(rustc_attrs)]
4+
5+
// Test to ensure that we can handle cases where
6+
// let statements create no bindings are intialized
7+
// using a Place expression
8+
//
9+
// Note: Currently when feature `capture_disjoint_fields` is enabled
10+
// we can't handle such cases. So the test so the test
11+
12+
struct Point {
13+
x: i32,
14+
y: i32,
15+
}
16+
17+
fn wild_struct() {
18+
let p = Point { x: 10, y: 20 };
19+
20+
let c = #[rustc_capture_analysis]
21+
//~^ ERROR: attributes on expressions are experimental
22+
|| {
23+
// FIXME(arora-aman): Change `_x` to `_`
24+
let Point { x: _x, y: _ } = p;
25+
//~^ ERROR: Capturing p[(0, 0)] -> ImmBorrow
26+
//~^^ ERROR: Min Capture p[(0, 0)] -> ImmBorrow
27+
};
28+
29+
c();
30+
}
31+
32+
fn wild_tuple() {
33+
let t = (String::new(), 10);
34+
35+
let c = #[rustc_capture_analysis]
36+
//~^ ERROR: attributes on expressions are experimental
37+
|| {
38+
// FIXME(arora-aman): Change `_x` to `_`
39+
let (_x, _) = t;
40+
//~^ ERROR: Capturing t[(0, 0)] -> ByValue
41+
//~^^ ERROR: Min Capture t[(0, 0)] -> ByValue
42+
};
43+
44+
c();
45+
}
46+
47+
fn wild_arr() {
48+
let arr = [String::new(), String::new()];
49+
50+
let c = #[rustc_capture_analysis]
51+
//~^ ERROR: attributes on expressions are experimental
52+
|| {
53+
// FIXME(arora-aman): Change `_x` to `_`
54+
let [_x, _] = arr;
55+
//~^ ERROR: Capturing arr[Index] -> ByValue
56+
//~^^ ERROR: Min Capture arr[] -> ByValue
57+
};
58+
59+
c();
60+
}
61+
62+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
error[E0658]: attributes on expressions are experimental
2+
--> $DIR/wild_patterns.rs:20:13
3+
|
4+
LL | let c = #[rustc_capture_analysis]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
8+
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
9+
10+
error[E0658]: attributes on expressions are experimental
11+
--> $DIR/wild_patterns.rs:35:13
12+
|
13+
LL | let c = #[rustc_capture_analysis]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
17+
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
18+
19+
error[E0658]: attributes on expressions are experimental
20+
--> $DIR/wild_patterns.rs:50:13
21+
|
22+
LL | let c = #[rustc_capture_analysis]
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
24+
|
25+
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
26+
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
27+
28+
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
29+
--> $DIR/wild_patterns.rs:1:12
30+
|
31+
LL | #![feature(capture_disjoint_fields)]
32+
| ^^^^^^^^^^^^^^^^^^^^^^^
33+
|
34+
= note: `#[warn(incomplete_features)]` on by default
35+
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
36+
37+
error: Capturing p[(0, 0)] -> ImmBorrow
38+
--> $DIR/wild_patterns.rs:24:37
39+
|
40+
LL | let Point { x: _x, y: _ } = p;
41+
| ^
42+
43+
error: Min Capture p[(0, 0)] -> ImmBorrow
44+
--> $DIR/wild_patterns.rs:24:37
45+
|
46+
LL | let Point { x: _x, y: _ } = p;
47+
| ^
48+
49+
error: Capturing t[(0, 0)] -> ByValue
50+
--> $DIR/wild_patterns.rs:39:23
51+
|
52+
LL | let (_x, _) = t;
53+
| ^
54+
55+
error: Min Capture t[(0, 0)] -> ByValue
56+
--> $DIR/wild_patterns.rs:39:23
57+
|
58+
LL | let (_x, _) = t;
59+
| ^
60+
61+
error: Capturing arr[Index] -> ByValue
62+
--> $DIR/wild_patterns.rs:54:23
63+
|
64+
LL | let [_x, _] = arr;
65+
| ^^^
66+
67+
error: Min Capture arr[] -> ByValue
68+
--> $DIR/wild_patterns.rs:54:23
69+
|
70+
LL | let [_x, _] = arr;
71+
| ^^^
72+
73+
error: aborting due to 9 previous errors; 1 warning emitted
74+
75+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)