]> git.lizzy.rs Git - rust.git/commit
forbid moves out of slices
authorAriel Ben-Yehuda <ariel.byd@gmail.com>
Sun, 24 Jul 2016 10:56:27 +0000 (13:56 +0300)
committerAriel Ben-Yehuda <arielb1@mail.tau.ac.il>
Fri, 16 Sep 2016 12:08:32 +0000 (15:08 +0300)
commit7b25e886028195a4f90c0baa5cc9101ebeceb5a3
tree7899d0115549790a45f227311015fe4733c9ca86
parenteb19cd65756cd285c81410e627752a75a41e3f0e
forbid moves out of slices

The wording of RFC #495 enables moves out of slices. Unfortuantely, non-zeroing
moves out of slices introduce a very annoying complication: as slices can
vary in their length, indexes from the start and end may or may not overlap
depending on the slice's exact length, which prevents assigning a particular
drop flag for each individual element.

For example, in the code

```Rust
fn foo<T>(a: Box<[Box<[T]>]>, c: bool) -> T {
    match (a, c) {
        (box [box [t, ..], ..], true) => t,
        (box [.., box [.., t]], false) => t,
        _ => panic!()
    }
}
```

If the condition is false, we have to drop the first element
of `a`, unless `a` has size 1 in which case we drop all the elements
of it but the last.

If someone comes with a nice way of handling it, we can always re-allow
moves out of slices.

This is a [breaking-change], but it is behind the `slice_patterns` feature
gate and was not allowed until recently.
src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs
src/librustc_borrowck/borrowck/gather_loans/move_error.rs
src/test/compile-fail/move-out-of-slice-1.rs [new file with mode: 0644]