1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
// Tests using a combination of pattern features has the expected borrow checking behavior
#![feature(box_patterns)]
enum Test {
Foo,
Bar,
_Baz,
}
// bindings_after_at + slice_patterns
fn bindings_after_at_slice_patterns_move_binding(x: [String; 4]) {
match x {
a @ [.., _] => (),
_ => (),
};
&x;
//~^ ERROR borrow of moved value
}
fn bindings_after_at_slice_patterns_borrows_binding_mut(mut x: [String; 4]) {
let r = match x {
ref mut foo @ [.., _] => Some(foo),
_ => None,
};
&x;
//~^ ERROR cannot borrow
drop(r);
}
fn bindings_after_at_slice_patterns_borrows_slice_mut1(mut x: [String; 4]) {
let r = match x {
ref foo @ [.., ref mut bar] => (),
//~^ ERROR cannot borrow
_ => (),
};
drop(r);
}
fn bindings_after_at_slice_patterns_borrows_slice_mut2(mut x: [String; 4]) {
let r = match x {
[ref foo @ .., ref bar] => Some(foo),
_ => None,
};
&mut x;
//~^ ERROR cannot borrow
drop(r);
}
fn bindings_after_at_slice_patterns_borrows_both(mut x: [String; 4]) {
let r = match x {
ref foo @ [.., ref bar] => Some(foo),
_ => None,
};
&mut x;
//~^ ERROR cannot borrow
drop(r);
}
// bindings_after_at + or_patterns
fn bindings_after_at_or_patterns_move(x: Option<Test>) {
match x {
foo @ Some(Test::Foo | Test::Bar) => (),
_ => (),
}
&x;
//~^ ERROR borrow of moved value
}
fn bindings_after_at_or_patterns_borrows(mut x: Option<Test>) {
let r = match x {
ref foo @ Some(Test::Foo | Test::Bar) => Some(foo),
_ => None,
};
&mut x;
//~^ ERROR cannot borrow
drop(r);
}
fn bindings_after_at_or_patterns_borrows_mut(mut x: Option<Test>) {
let r = match x {
ref mut foo @ Some(Test::Foo | Test::Bar) => Some(foo),
_ => None,
};
&x;
//~^ ERROR cannot borrow
drop(r);
}
// bindings_after_at + box_patterns
fn bindings_after_at_box_patterns_borrows_both(mut x: Option<Box<String>>) {
let r = match x {
ref foo @ Some(box ref s) => Some(foo),
_ => None,
};
&mut x;
//~^ ERROR cannot borrow
drop(r);
}
fn bindings_after_at_box_patterns_borrows_mut(mut x: Option<Box<String>>) {
match x {
ref foo @ Some(box ref mut s) => (),
//~^ ERROR cannot borrow
_ => (),
};
}
// bindings_after_at + slice_patterns + or_patterns
fn bindings_after_at_slice_patterns_or_patterns_moves(x: [Option<Test>; 4]) {
match x {
a @ [.., Some(Test::Foo | Test::Bar)] => (),
_ => (),
};
&x;
//~^ ERROR borrow of moved value
}
fn bindings_after_at_slice_patterns_or_patterns_borrows_binding(mut x: [Option<Test>; 4]) {
let r = match x {
ref a @ [ref b @ .., Some(Test::Foo | Test::Bar)] => Some(a),
_ => None,
};
&mut x;
//~^ ERROR cannot borrow
drop(r);
}
fn bindings_after_at_slice_patterns_or_patterns_borrows_slice(mut x: [Option<Test>; 4]) {
let r = match x {
ref a @ [ref b @ .., Some(Test::Foo | Test::Bar)] => Some(b),
_ => None,
};
&mut x;
//~^ ERROR cannot borrow
drop(r);
}
// bindings_after_at + slice_patterns + box_patterns
fn bindings_after_at_slice_patterns_box_patterns_borrows(mut x: [Option<Box<String>>; 4]) {
let r = match x {
[_, ref a @ Some(box ref b), ..] => Some(a),
_ => None,
};
&mut x;
//~^ ERROR cannot borrow
drop(r);
}
// bindings_after_at + slice_patterns + or_patterns + box_patterns
fn bindings_after_at_slice_patterns_or_patterns_box_patterns_borrows(
mut x: [Option<Box<Test>>; 4]
) {
let r = match x {
[_, ref a @ Some(box Test::Foo | box Test::Bar), ..] => Some(a),
_ => None,
};
&mut x;
//~^ ERROR cannot borrow
drop(r);
}
fn bindings_after_at_slice_patterns_or_patterns_box_patterns_borrows_mut(
mut x: [Option<Box<Test>>; 4]
) {
let r = match x {
[_, ref mut a @ Some(box Test::Foo | box Test::Bar), ..] => Some(a),
_ => None,
};
&x;
//~^ ERROR cannot borrow
drop(r);
}
fn bindings_after_at_slice_patterns_or_patterns_box_patterns_borrows_binding(
mut x: [Option<Box<Test>>; 4]
) {
let r = match x {
ref a @ [_, ref b @ Some(box Test::Foo | box Test::Bar), ..] => Some(a),
_ => None,
};
&mut x;
//~^ ERROR cannot borrow
drop(r);
}
fn main() {}
|