1 // Tests using a combination of pattern features has the expected borrow checking behavior
2 #![feature(bindings_after_at)]
3 #![feature(or_patterns)]
4 #![feature(box_patterns)]
12 // bindings_after_at + slice_patterns
14 fn bindings_after_at_slice_patterns_move_binding(x: [String; 4]) {
21 //~^ ERROR borrow of moved value
24 fn bindings_after_at_slice_patterns_borrows_binding_mut(mut x: [String; 4]) {
26 ref mut foo @ [.., _] => Some(foo),
31 //~^ ERROR cannot borrow
36 fn bindings_after_at_slice_patterns_borrows_slice_mut1(mut x: [String; 4]) {
38 ref foo @ [.., ref mut bar] => (),
39 //~^ ERROR cannot borrow
46 fn bindings_after_at_slice_patterns_borrows_slice_mut2(mut x: [String; 4]) {
48 [ref foo @ .., ref bar] => Some(foo),
53 //~^ ERROR cannot borrow
58 fn bindings_after_at_slice_patterns_borrows_both(mut x: [String; 4]) {
60 ref foo @ [.., ref bar] => Some(foo),
65 //~^ ERROR cannot borrow
70 // bindings_after_at + or_patterns
72 fn bindings_after_at_or_patterns_move(x: Option<Test>) {
74 foo @ Some(Test::Foo | Test::Bar) => (),
79 //~^ ERROR borrow of moved value
82 fn bindings_after_at_or_patterns_borrows(mut x: Option<Test>) {
84 ref foo @ Some(Test::Foo | Test::Bar) => Some(foo),
89 //~^ ERROR cannot borrow
94 fn bindings_after_at_or_patterns_borrows_mut(mut x: Option<Test>) {
96 ref mut foo @ Some(Test::Foo | Test::Bar) => Some(foo),
101 //~^ ERROR cannot borrow
106 // bindings_after_at + box_patterns
108 fn bindings_after_at_box_patterns_borrows_both(mut x: Option<Box<String>>) {
110 ref foo @ Some(box ref s) => Some(foo),
115 //~^ ERROR cannot borrow
120 fn bindings_after_at_box_patterns_borrows_mut(mut x: Option<Box<String>>) {
122 ref foo @ Some(box ref mut s) => (),
123 //~^ ERROR cannot borrow
128 // bindings_after_at + slice_patterns + or_patterns
130 fn bindings_after_at_slice_patterns_or_patterns_moves(x: [Option<Test>; 4]) {
132 a @ [.., Some(Test::Foo | Test::Bar)] => (),
137 //~^ ERROR borrow of moved value
140 fn bindings_after_at_slice_patterns_or_patterns_borrows_binding(mut x: [Option<Test>; 4]) {
142 ref a @ [ref b @ .., Some(Test::Foo | Test::Bar)] => Some(a),
147 //~^ ERROR cannot borrow
152 fn bindings_after_at_slice_patterns_or_patterns_borrows_slice(mut x: [Option<Test>; 4]) {
154 ref a @ [ref b @ .., Some(Test::Foo | Test::Bar)] => Some(b),
159 //~^ ERROR cannot borrow
164 // bindings_after_at + slice_patterns + box_patterns
166 fn bindings_after_at_slice_patterns_box_patterns_borrows(mut x: [Option<Box<String>>; 4]) {
168 [_, ref a @ Some(box ref b), ..] => Some(a),
173 //~^ ERROR cannot borrow
178 // bindings_after_at + slice_patterns + or_patterns + box_patterns
180 fn bindings_after_at_slice_patterns_or_patterns_box_patterns_borrows(
181 mut x: [Option<Box<Test>>; 4]
184 [_, ref a @ Some(box Test::Foo | box Test::Bar), ..] => Some(a),
189 //~^ ERROR cannot borrow
194 fn bindings_after_at_slice_patterns_or_patterns_box_patterns_borrows_mut(
195 mut x: [Option<Box<Test>>; 4]
198 [_, ref mut a @ Some(box Test::Foo | box Test::Bar), ..] => Some(a),
203 //~^ ERROR cannot borrow
208 fn bindings_after_at_slice_patterns_or_patterns_box_patterns_borrows_binding(
209 mut x: [Option<Box<Test>>; 4]
212 ref a @ [_, ref b @ Some(box Test::Foo | box Test::Bar), ..] => Some(a),
217 //~^ ERROR cannot borrow