|
11 | 11 | // revisions: ast mir
|
12 | 12 | //[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir
|
13 | 13 |
|
| 14 | +#![feature(advanced_slice_patterns)] |
| 15 | + |
14 | 16 | pub struct Foo {
|
15 | 17 | x: u32
|
16 | 18 | }
|
@@ -163,4 +165,37 @@ fn main() {
|
163 | 165 | //[mir]~^ ERROR cannot use `u.a` because it was mutably borrowed (Ast)
|
164 | 166 | //[mir]~| ERROR cannot use `u.a` because it was mutably borrowed (Mir)
|
165 | 167 | }
|
| 168 | + // Constant index |
| 169 | + { |
| 170 | + let mut v = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
| 171 | + let _v = &mut v; |
| 172 | + match v { |
| 173 | + &[x, _, .., _, _] => println!("{}", x), |
| 174 | + //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed |
| 175 | + //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast) |
| 176 | + //[mir]~| ERROR cannot use `v[0]` because it was mutably borrowed (Mir) |
| 177 | + _ => panic!("other case"), |
| 178 | + } |
| 179 | + match v { |
| 180 | + &[_, x, .., _, _] => println!("{}", x), |
| 181 | + //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed |
| 182 | + //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast) |
| 183 | + //[mir]~| ERROR cannot use `v[1]` because it was mutably borrowed (Mir) |
| 184 | + _ => panic!("other case"), |
| 185 | + } |
| 186 | + match v { |
| 187 | + &[_, _, .., x, _] => println!("{}", x), |
| 188 | + //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed |
| 189 | + //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast) |
| 190 | + //[mir]~| ERROR cannot use `v[-2]` because it was mutably borrowed (Mir) |
| 191 | + _ => panic!("other case"), |
| 192 | + } |
| 193 | + match v { |
| 194 | + &[_, _, .., _, x] => println!("{}", x), |
| 195 | + //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed |
| 196 | + //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast) |
| 197 | + //[mir]~| ERROR cannot use `v[-1]` because it was mutably borrowed (Mir) |
| 198 | + _ => panic!("other case"), |
| 199 | + } |
| 200 | + } |
166 | 201 | }
|
0 commit comments