Skip to content

Commit 68485b4

Browse files
authored
Rollup merge of #86549 - mbartlett21:patch-1, r=GuillaumeGomez
Add destructuring example of E0508 This adds an example that destructures the array to move the value, instead of taking a reference or cloning.
2 parents f19aad8 + 9db5c48 commit 68485b4

File tree

1 file changed

+13
-0
lines changed
  • compiler/rustc_error_codes/src/error_codes

1 file changed

+13
-0
lines changed

compiler/rustc_error_codes/src/error_codes/E0508.md

+13
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,16 @@ fn main() {
3939
let _value = array[0].clone();
4040
}
4141
```
42+
43+
If you really want to move the value out, you can use a destructuring array
44+
pattern to move it:
45+
46+
```
47+
struct NonCopy;
48+
49+
fn main() {
50+
let array = [NonCopy; 1];
51+
// Destructuring the array
52+
let [_value] = array;
53+
}
54+
```

0 commit comments

Comments
 (0)