File tree Expand file tree Collapse file tree 1 file changed +41
-6
lines changed
tests/ui/pattern/bindings-after-at Expand file tree Collapse file tree 1 file changed +41
-6
lines changed Original file line number Diff line number Diff line change 1
- // run-pass
1
+ #! [ allow ( unused ) ]
2
2
3
3
// Test copy
4
4
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
+ }
10
25
26
+ #[ rustfmt:: skip]
11
27
pub fn main ( ) {
12
28
match ( A { a : 10 , b : 20 } ) {
13
29
x@A { a, b : 20 } => { assert ! ( x. a == 10 ) ; assert ! ( a == 10 ) ; }
@@ -23,6 +39,25 @@ pub fn main() {
23
39
y. d . c = 30 ;
24
40
assert_eq ! ( d. c, 20 ) ;
25
41
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
+
26
61
let some_b = Some ( B { a : 10 , b : C { c : 20 } } ) ;
27
62
28
63
// in irrefutable pattern
You can’t perform that action at this time.
0 commit comments