Skip to content

cannot move into irrefutable slice patterns with multiple elements #26736

Closed
@oli-obk

Description

@oli-obk
let arr = [Box::new(1), Box::new(2), Box::new(3)];
let [a, b, c] = arr;

fails with

<anon>:5:13: 5:14 error: use of moved value: `arr[..]` [E0382]
<anon>:5     let [a, b, c] = arr;
                     ^
<anon>:5:10: 5:11 note: `arr[..]` moved here because it has type `Box<i32>`, which is moved by default
<anon>:5     let [a, b, c] = arr;
                  ^
<anon>:5:10: 5:11 help: use `ref` to override

while the following work fine:

let arr = [Box::new(1)];
let [a] = arr;
enum Dummy<T> {
    Val([T; 2]),
}
let arr = [Box::new(1), Box::new(2)];
let Dummy::Val([a, b]) = Dummy::Val(arr);

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerC-bugCategory: This is a bug.fixed-by-NLLBugs fixed, but only when NLL is enabled.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions