Add tests
This commit is contained in:
parent
cd6d8f2a04
commit
3ea464f36a
@ -1,13 +1,29 @@
|
|||||||
// run-pass
|
#![allow(unused)]
|
||||||
|
|
||||||
// Test copy
|
// Test copy
|
||||||
|
|
||||||
struct A { a: i32, b: i32 }
|
struct A {
|
||||||
struct B { a: i32, b: C }
|
a: i32,
|
||||||
struct D { a: i32, d: C }
|
b: i32,
|
||||||
#[derive(Copy,Clone)]
|
}
|
||||||
struct C { c: i32 }
|
struct B {
|
||||||
|
a: i32,
|
||||||
|
b: C,
|
||||||
|
}
|
||||||
|
struct D {
|
||||||
|
a: i32,
|
||||||
|
d: C,
|
||||||
|
}
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
struct C {
|
||||||
|
c: i32,
|
||||||
|
}
|
||||||
|
enum E {
|
||||||
|
E { a: i32, e: C },
|
||||||
|
NotE,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
match (A {a: 10, b: 20}) {
|
match (A {a: 10, b: 20}) {
|
||||||
x@A {a, b: 20} => { assert!(x.a == 10); assert!(a == 10); }
|
x@A {a, b: 20} => { assert!(x.a == 10); assert!(a == 10); }
|
||||||
@ -23,6 +39,25 @@ pub fn main() {
|
|||||||
y.d.c = 30;
|
y.d.c = 30;
|
||||||
assert_eq!(d.c, 20);
|
assert_eq!(d.c, 20);
|
||||||
|
|
||||||
|
match (E::E { a: 10, e: C { c: 20 } }) {
|
||||||
|
x @ E::E{ a, e: C { c } } => {
|
||||||
|
//~^ ERROR use of moved value
|
||||||
|
assert!(matches!(x, E::E { a: 10, e: C { c: 20 } }));
|
||||||
|
assert!(a == 10);
|
||||||
|
assert!(c == 20);
|
||||||
|
}
|
||||||
|
_ => panic!(),
|
||||||
|
}
|
||||||
|
match (E::E { a: 10, e: C { c: 20 } }) {
|
||||||
|
mut x @ E::E{ a, e: C { mut c } } => {
|
||||||
|
//~^ ERROR use of moved value
|
||||||
|
x = E::NotE;
|
||||||
|
c += 30;
|
||||||
|
assert_eq!(c, 50);
|
||||||
|
}
|
||||||
|
_ => panic!(),
|
||||||
|
}
|
||||||
|
|
||||||
let some_b = Some(B { a: 10, b: C { c: 20 } });
|
let some_b = Some(B { a: 10, b: C { c: 20 } });
|
||||||
|
|
||||||
// in irrefutable pattern
|
// in irrefutable pattern
|
||||||
|
Loading…
x
Reference in New Issue
Block a user