1 // Tests using a combination of pattern features has the expected borrow checking behavior
2 #![feature(box_patterns)]
10 // bindings_after_at + slice_patterns
12 fn bindings_after_at_slice_patterns_move_binding(x: [String; 4]) {
19 //~^ ERROR borrow of moved value
22 fn bindings_after_at_slice_patterns_borrows_binding_mut(mut x: [String; 4]) {
24 ref mut foo @ [.., _] => Some(foo),
29 //~^ ERROR cannot borrow
34 fn bindings_after_at_slice_patterns_borrows_slice_mut1(mut x: [String; 4]) {
36 ref foo @ [.., ref mut bar] => (),
37 //~^ ERROR cannot borrow
44 fn bindings_after_at_slice_patterns_borrows_slice_mut2(mut x: [String; 4]) {
46 [ref foo @ .., ref bar] => Some(foo),
51 //~^ ERROR cannot borrow
56 fn bindings_after_at_slice_patterns_borrows_both(mut x: [String; 4]) {
58 ref foo @ [.., ref bar] => Some(foo),
63 //~^ ERROR cannot borrow
68 // bindings_after_at + or_patterns
70 fn bindings_after_at_or_patterns_move(x: Option<Test>) {
72 foo @ Some(Test::Foo | Test::Bar) => (),
77 //~^ ERROR borrow of moved value
80 fn bindings_after_at_or_patterns_borrows(mut x: Option<Test>) {
82 ref foo @ Some(Test::Foo | Test::Bar) => Some(foo),
87 //~^ ERROR cannot borrow
92 fn bindings_after_at_or_patterns_borrows_mut(mut x: Option<Test>) {
94 ref mut foo @ Some(Test::Foo | Test::Bar) => Some(foo),
99 //~^ ERROR cannot borrow
104 // bindings_after_at + box_patterns
106 fn bindings_after_at_box_patterns_borrows_both(mut x: Option<Box<String>>) {
108 ref foo @ Some(box ref s) => Some(foo),
113 //~^ ERROR cannot borrow
118 fn bindings_after_at_box_patterns_borrows_mut(mut x: Option<Box<String>>) {
120 ref foo @ Some(box ref mut s) => (),
121 //~^ ERROR cannot borrow
126 // bindings_after_at + slice_patterns + or_patterns
128 fn bindings_after_at_slice_patterns_or_patterns_moves(x: [Option<Test>; 4]) {
130 a @ [.., Some(Test::Foo | Test::Bar)] => (),
135 //~^ ERROR borrow of moved value
138 fn bindings_after_at_slice_patterns_or_patterns_borrows_binding(mut x: [Option<Test>; 4]) {
140 ref a @ [ref b @ .., Some(Test::Foo | Test::Bar)] => Some(a),
145 //~^ ERROR cannot borrow
150 fn bindings_after_at_slice_patterns_or_patterns_borrows_slice(mut x: [Option<Test>; 4]) {
152 ref a @ [ref b @ .., Some(Test::Foo | Test::Bar)] => Some(b),
157 //~^ ERROR cannot borrow
162 // bindings_after_at + slice_patterns + box_patterns
164 fn bindings_after_at_slice_patterns_box_patterns_borrows(mut x: [Option<Box<String>>; 4]) {
166 [_, ref a @ Some(box ref b), ..] => Some(a),
171 //~^ ERROR cannot borrow
176 // bindings_after_at + slice_patterns + or_patterns + box_patterns
178 fn bindings_after_at_slice_patterns_or_patterns_box_patterns_borrows(
179 mut x: [Option<Box<Test>>; 4]
182 [_, ref a @ Some(box Test::Foo | box Test::Bar), ..] => Some(a),
187 //~^ ERROR cannot borrow
192 fn bindings_after_at_slice_patterns_or_patterns_box_patterns_borrows_mut(
193 mut x: [Option<Box<Test>>; 4]
196 [_, ref mut a @ Some(box Test::Foo | box Test::Bar), ..] => Some(a),
201 //~^ ERROR cannot borrow
206 fn bindings_after_at_slice_patterns_or_patterns_box_patterns_borrows_binding(
207 mut x: [Option<Box<Test>>; 4]
210 ref a @ [_, ref b @ Some(box Test::Foo | box Test::Bar), ..] => Some(a),
215 //~^ ERROR cannot borrow