File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
src/test/ui/pattern/bindings-after-at Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ // run-pass
2+
3+ // Test copy
4+
5+ #![ feature( bindings_after_at) ]
6+
7+ struct A { a : i32 , b : i32 }
8+ struct B { a : i32 , b : C }
9+ struct D { a : i32 , d : C }
10+ #[ derive( Copy , Clone ) ]
11+ struct C { c : i32 }
12+
13+ pub fn main ( ) {
14+ match ( A { a : 10 , b : 20 } ) {
15+ x@A { a, b : 20 } => { assert ! ( x. a == 10 ) ; assert ! ( a == 10 ) ; }
16+ A { b : _b, ..} => { panic ! ( ) ; }
17+ }
18+
19+ let mut x@B { b, ..} = B { a : 10 , b : C { c : 20 } } ;
20+ assert_eq ! ( x. a, 10 ) ;
21+ x. b . c = 30 ;
22+ assert_eq ! ( b. c, 20 ) ;
23+ let mut y@D { d, ..} = D { a : 10 , d : C { c : 20 } } ;
24+ assert_eq ! ( y. a, 10 ) ;
25+ y. d . c = 30 ;
26+ assert_eq ! ( d. c, 20 ) ;
27+
28+ let some_b = Some ( B { a : 10 , b : C { c : 20 } } ) ;
29+
30+ // in irrefutable pattern
31+ if let Some ( x @ B { b, .. } ) = some_b {
32+ assert_eq ! ( x. b. c, 20 ) ;
33+ assert_eq ! ( b. c, 20 ) ;
34+ } else {
35+ unreachable ! ( ) ;
36+ }
37+
38+ let some_b = Some ( B { a : 10 , b : C { c : 20 } } ) ;
39+
40+ if let Some ( x @ B { b : mut b @ C { c } , .. } ) = some_b {
41+ assert_eq ! ( x. b. c, 20 ) ;
42+ assert_eq ! ( b. c, 20 ) ;
43+ b. c = 30 ;
44+ assert_eq ! ( b. c, 30 ) ;
45+ assert_eq ! ( c, 20 ) ;
46+ } else {
47+ unreachable ! ( ) ;
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments