|
8 | 8 | // option. This file may not be copied, modified, or distributed
|
9 | 9 | // except according to those terms.
|
10 | 10 |
|
| 11 | +// ignore-tidy-linelength |
11 | 12 | // revisions: ast mir
|
12 | 13 | //[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir
|
13 | 14 |
|
| 15 | +#![feature(slice_patterns)] |
14 | 16 | #![feature(advanced_slice_patterns)]
|
15 | 17 |
|
16 | 18 | pub struct Foo {
|
@@ -173,29 +175,62 @@ fn main() {
|
173 | 175 | &[x, _, .., _, _] => println!("{}", x),
|
174 | 176 | //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed
|
175 | 177 | //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast)
|
176 |
| - //[mir]~| ERROR cannot use `v[0]` because it was mutably borrowed (Mir) |
| 178 | + //[mir]~| ERROR cannot use `v[..]` because it was mutably borrowed (Mir) |
177 | 179 | _ => panic!("other case"),
|
178 | 180 | }
|
179 | 181 | match v {
|
180 | 182 | &[_, x, .., _, _] => println!("{}", x),
|
181 | 183 | //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed
|
182 | 184 | //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast)
|
183 |
| - //[mir]~| ERROR cannot use `v[1]` because it was mutably borrowed (Mir) |
| 185 | + //[mir]~| ERROR cannot use `v[..]` because it was mutably borrowed (Mir) |
184 | 186 | _ => panic!("other case"),
|
185 | 187 | }
|
186 | 188 | match v {
|
187 | 189 | &[_, _, .., x, _] => println!("{}", x),
|
188 | 190 | //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed
|
189 | 191 | //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast)
|
190 |
| - //[mir]~| ERROR cannot use `v[-2]` because it was mutably borrowed (Mir) |
| 192 | + //[mir]~| ERROR cannot use `v[..]` because it was mutably borrowed (Mir) |
191 | 193 | _ => panic!("other case"),
|
192 | 194 | }
|
193 | 195 | match v {
|
194 | 196 | &[_, _, .., _, x] => println!("{}", x),
|
195 | 197 | //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed
|
196 | 198 | //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast)
|
197 |
| - //[mir]~| ERROR cannot use `v[-1]` because it was mutably borrowed (Mir) |
| 199 | + //[mir]~| ERROR cannot use `v[..]` because it was mutably borrowed (Mir) |
198 | 200 | _ => panic!("other case"),
|
199 | 201 | }
|
200 | 202 | }
|
| 203 | + // Subslices |
| 204 | + { |
| 205 | + let mut v = &[1, 2, 3, 4, 5]; |
| 206 | + let _v = &mut v; |
| 207 | + match v { |
| 208 | + &[x..] => println!("{:?}", x), |
| 209 | + //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed |
| 210 | + //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast) |
| 211 | + //[mir]~| ERROR cannot use `v[..]` because it was mutably borrowed (Mir) |
| 212 | + _ => panic!("other case"), |
| 213 | + } |
| 214 | + match v { |
| 215 | + &[_, x..] => println!("{:?}", x), |
| 216 | + //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed |
| 217 | + //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast) |
| 218 | + //[mir]~| ERROR cannot use `v[..]` because it was mutably borrowed (Mir) |
| 219 | + _ => panic!("other case"), |
| 220 | + } |
| 221 | + match v { |
| 222 | + &[x.., _] => println!("{:?}", x), |
| 223 | + //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed |
| 224 | + //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast) |
| 225 | + //[mir]~| ERROR cannot use `v[..]` because it was mutably borrowed (Mir) |
| 226 | + _ => panic!("other case"), |
| 227 | + } |
| 228 | + match v { |
| 229 | + &[_, x.., _] => println!("{:?}", x), |
| 230 | + //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed |
| 231 | + //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast) |
| 232 | + //[mir]~| ERROR cannot use `v[..]` because it was mutably borrowed (Mir) |
| 233 | + _ => panic!("other case"), |
| 234 | + } |
| 235 | + } |
201 | 236 | }
|
0 commit comments