Skip to content

Commit a8c0f07

Browse files
committed
Run pass test cases for RFC 2229
1 parent 08fb1ec commit a8c0f07

21 files changed

+483
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// run-pass
2+
3+
#![feature(capture_disjoint_fields)]
4+
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
5+
//~| NOTE: `#[warn(incomplete_features)]` on by default
6+
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
7+
8+
struct Point {
9+
x: i32,
10+
y: i32,
11+
}
12+
13+
fn main() {
14+
let mut p = Point { x: 10, y: 10 };
15+
16+
let c = || {
17+
println!("{}", p.x);
18+
};
19+
20+
// `c` should only capture `p.x`, therefore mutating `p.y` is allowed.
21+
let py = &mut p.y;
22+
23+
c();
24+
*py = 20;
25+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/capture-disjoint-field-struct.rs:3:12
3+
|
4+
LL | #![feature(capture_disjoint_fields)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
9+
10+
warning: 1 warning emitted
11+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// run-pass
2+
3+
#![feature(capture_disjoint_fields)]
4+
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
5+
//~| NOTE: `#[warn(incomplete_features)]` on by default
6+
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
7+
#![feature(rustc_attrs)]
8+
9+
fn main() {
10+
let mut t = (10, 10);
11+
12+
let mut c = || {
13+
let t1 = &mut t.1;
14+
*t1 = 20;
15+
};
16+
17+
// `c` only captures t.1, therefore reading t.0 is allowed.
18+
println!("{}", t.0);
19+
c();
20+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/capture-disjoint-field-tuple-mut.rs:3:12
3+
|
4+
LL | #![feature(capture_disjoint_fields)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
9+
10+
warning: 1 warning emitted
11+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// run-pass
2+
3+
#![feature(capture_disjoint_fields)]
4+
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
5+
//~| NOTE: `#[warn(incomplete_features)]` on by default
6+
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
7+
#![feature(rustc_attrs)]
8+
9+
fn main() {
10+
let mut t = (10, 10);
11+
12+
let c = || {
13+
println!("{}", t.0);
14+
};
15+
16+
// `c` only captures t.0, therefore mutating t.1 is allowed.
17+
let t1 = &mut t.1;
18+
19+
c();
20+
*t1 = 20;
21+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/capture-disjoint-field-tuple.rs:3:12
3+
|
4+
LL | #![feature(capture_disjoint_fields)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
9+
10+
warning: 1 warning emitted
11+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// run-pas
2+
3+
#![feature(capture_disjoint_fields)]
4+
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
5+
//~| NOTE: `#[warn(incomplete_features)]` on by default
6+
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
7+
8+
// FIXME(rust-lang/project-rfc-2229#24) Currently when feature `capture_disjoint_fields`
9+
// is enabled we can't handle wild card in patterns.
10+
11+
enum Info {
12+
Point(i32, i32, String),
13+
Meta(String, Vec<(i32, i32)>)
14+
}
15+
16+
fn multi_variant_enum() {
17+
let point = Info::Point(10, -10, "1".into());
18+
19+
let vec = Vec::new();
20+
let meta = Info::Meta("meta".into(), vec);
21+
22+
let c = || {
23+
if let Info::Point(_, _, str) = point {
24+
println!("{}", str);
25+
}
26+
27+
if let Info::Meta(_, v) = meta {
28+
println!("{:?}", v);
29+
}
30+
};
31+
32+
c();
33+
}
34+
35+
enum SingleVariant {
36+
Point(i32, i32, String),
37+
}
38+
39+
fn single_variant_enum() {
40+
let point = SingleVariant::Point(10, -10, "1".into());
41+
42+
let c = || {
43+
let SingleVariant::Point(_, _, str) = point;
44+
println!("{}", str);
45+
};
46+
47+
c();
48+
let SingleVariant::Point(a, b, _) = point;
49+
println!("{} {}", a, b);
50+
}
51+
52+
fn main() {}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// run-pass
2+
#![feature(capture_disjoint_fields)]
3+
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
4+
//~| NOTE: `#[warn(incomplete_features)]` on by default
5+
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
6+
#![feature(rustc_attrs)]
7+
8+
// FIXME(rust-lang/project-rfc-2229#24) Currently when feature `capture_disjoint_fields`
9+
// is enabled we can't handle wild card in patterns.
10+
11+
struct Point {
12+
x: i32,
13+
y: i32,
14+
id: String,
15+
}
16+
17+
fn structs() {
18+
let mut p = Point { x: 10, y: 10, id: String::new() };
19+
20+
let c = || {
21+
let Point { x: ref mut x, y: _, id: moved_id } = p;
22+
23+
println!("{}, {}", x, moved_id);
24+
};
25+
26+
c();
27+
println!("{:?}", p.y);
28+
}
29+
30+
fn tuples() {
31+
let mut t = (10, String::new(), (String::new(), 42));
32+
33+
let c = || {
34+
let (ref mut x, ref ref_str, (moved_s, _)) = t;
35+
println!("{}, {} {}", x, ref_str, moved_s);
36+
};
37+
38+
c();
39+
println!("{:?}", t.2.1);
40+
}
41+
42+
fn main() {}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// run-pass
2+
3+
#![feature(capture_disjoint_fields)]
4+
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
5+
//~| NOTE: `#[warn(incomplete_features)]` on by default
6+
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
7+
8+
// Tests that if a closure uses disjoint fields of the same object
9+
// then that case is handled properly.
10+
11+
#![allow(unused)]
12+
13+
struct Struct {
14+
x: i32,
15+
y: i32,
16+
s: String,
17+
}
18+
19+
fn main() {
20+
let mut s = Struct { x: 10, y: 10, s: String::new() };
21+
22+
let mut c = {
23+
s.x += 10;
24+
s.y += 42;
25+
s.s = String::from("new");
26+
};
27+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/disjoint-capture-in-same-closure.rs:3:12
3+
|
4+
LL | #![feature(capture_disjoint_fields)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
9+
10+
warning: 1 warning emitted
11+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// run-pass
2+
3+
#![feature(capture_disjoint_fields)]
4+
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
5+
//~| NOTE: `#[warn(incomplete_features)]` on by default
6+
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
7+
8+
struct Filter {
9+
div: i32,
10+
}
11+
impl Filter {
12+
fn allowed(&self, x: i32) -> bool {
13+
x % self.div == 1
14+
}
15+
}
16+
17+
struct Data {
18+
filter: Filter,
19+
list: Vec<i32>,
20+
}
21+
impl Data {
22+
fn update(&mut self) {
23+
// The closure passed to filter only captures self.filter,
24+
// therefore mutating self.list is allowed.
25+
self.list.retain(
26+
|v| self.filter.allowed(*v),
27+
);
28+
}
29+
}
30+
31+
fn main() {
32+
let mut d = Data { filter: Filter { div: 3 }, list: Vec::new() };
33+
34+
for i in 1..10 {
35+
d.list.push(i);
36+
}
37+
38+
d.update();
39+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/filter-on-struct-member.rs:3:12
3+
|
4+
LL | #![feature(capture_disjoint_fields)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
9+
10+
warning: 1 warning emitted
11+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// run-pass
2+
3+
#![feature(capture_disjoint_fields)]
4+
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
5+
//~| NOTE: `#[warn(incomplete_features)]` on by default
6+
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
7+
#![allow(unused)]
8+
9+
struct Point {
10+
x: i32,
11+
y: i32,
12+
}
13+
struct Wrapper {
14+
p: Point,
15+
}
16+
17+
fn main() {
18+
let mut w = Wrapper { p: Point { x: 10, y: 10 } };
19+
20+
let mut c = || {
21+
w.p.x += 20;
22+
};
23+
24+
// `c` only captures `w.p.x`, therefore it's safe to mutate `w.p.y`.
25+
let py = &mut w.p.y;
26+
c();
27+
28+
*py = 20
29+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/multilevel-path-1.rs:3:12
3+
|
4+
LL | #![feature(capture_disjoint_fields)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
9+
10+
warning: 1 warning emitted
11+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// run-pass
2+
3+
#![feature(capture_disjoint_fields)]
4+
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
5+
//~| NOTE: `#[warn(incomplete_features)]` on by default
6+
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
7+
#![allow(unused)]
8+
9+
struct Point {
10+
x: i32,
11+
y: i32,
12+
}
13+
struct Wrapper {
14+
p: Point,
15+
}
16+
17+
fn main() {
18+
let mut w = Wrapper { p: Point { x: 10, y: 10 } };
19+
20+
let c = || {
21+
println!("{}", w.p.x);
22+
};
23+
24+
// `c` only captures `w.p.x`, therefore it's safe to mutate `w.p.y`.
25+
let py = &mut w.p.y;
26+
c();
27+
28+
*py = 20
29+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/multilevel-path-2.rs:3:12
3+
|
4+
LL | #![feature(capture_disjoint_fields)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
9+
10+
warning: 1 warning emitted
11+

0 commit comments

Comments
 (0)