You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Slice patterns cannot be used to destructure arrays of non-Copy types:
struct Struct;
fn main() {
let x = [Struct, Struct];
let [a, b] = x;
}
error[E0382]: use of moved value: `x[..]`
--> src/main.rs:5:13
|
5 | let [a, b] = x;
| - ^ value used here after move
| |
| value moved here
|
= note: move occurs because `x[..]` has type `Struct`, which does not implement the `Copy` trait
This makes array destructuring pretty redundant IMHO as moving out of a Copy array could already be done through indexing; moving out of a non-Copy array cannot be done but destructuring provides a safe syntax to do so.
On a related note, the following code fails to compile:
struct Struct;
fn main() {
let x = [Struct, Struct];
let a = x[0];
}
This should at the very least compile in the same way as
struct Struct;
fn main() {
let x = [Struct, Struct];
let [a, _] = x;
}
Which does compile correctly in rust 1.26.
The text was updated successfully, but these errors were encountered:
I'm not sure that this is really a duplicate, as #26736 is now resolved but the above example fails to compile on 1.45.0-nightly (2020-05-27 664fcd3f046e2a682460).
Slice patterns cannot be used to destructure arrays of non-
Copy
types:This makes array destructuring pretty redundant IMHO as moving out of a
Copy
array could already be done through indexing; moving out of a non-Copy
array cannot be done but destructuring provides a safe syntax to do so.On a related note, the following code fails to compile:
This should at the very least compile in the same way as
Which does compile correctly in rust 1.26.
The text was updated successfully, but these errors were encountered: