Skip to content

Commit 0b0375d

Browse files
committed
Add tests
1 parent d9d89fd commit 0b0375d

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

tests/ui/pattern/bindings-after-at/bind-by-copy.rs

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1-
// run-pass
1+
#![allow(unused)]
22

33
// Test copy
44

5-
struct A { a: i32, b: i32 }
6-
struct B { a: i32, b: C }
7-
struct D { a: i32, d: C }
8-
#[derive(Copy,Clone)]
9-
struct C { c: i32 }
5+
struct A {
6+
a: i32,
7+
b: i32,
8+
}
9+
struct B {
10+
a: i32,
11+
b: C,
12+
}
13+
struct D {
14+
a: i32,
15+
d: C,
16+
}
17+
#[derive(Copy, Clone)]
18+
struct C {
19+
c: i32,
20+
}
21+
enum E {
22+
E { a: i32, e: C },
23+
NotE,
24+
}
1025

26+
#[rustfmt::skip]
1127
pub fn main() {
1228
match (A {a: 10, b: 20}) {
1329
x@A {a, b: 20} => { assert!(x.a == 10); assert!(a == 10); }
@@ -23,6 +39,25 @@ pub fn main() {
2339
y.d.c = 30;
2440
assert_eq!(d.c, 20);
2541

42+
match (E::E { a: 10, e: C { c: 20 } }) {
43+
x @ E::E{ a, e: C { c } } => {
44+
//~^ ERROR use of moved value
45+
assert!(matches!(x, E::E { a: 10, e: C { c: 20 } }));
46+
assert!(a == 10);
47+
assert!(c == 20);
48+
}
49+
_ => panic!(),
50+
}
51+
match (E::E { a: 10, e: C { c: 20 } }) {
52+
mut x @ E::E{ a, e: C { mut c } } => {
53+
//~^ ERROR use of moved value
54+
x = E::NotE;
55+
c += 30;
56+
assert_eq!(c, 50);
57+
}
58+
_ => panic!(),
59+
}
60+
2661
let some_b = Some(B { a: 10, b: C { c: 20 } });
2762

2863
// in irrefutable pattern

0 commit comments

Comments
 (0)