Skip to content

Commit 9db5c48

Browse files
authoredJun 22, 2021
Add destructuring example of E0508
This adds an example that destructures the array to move the value, instead of taking a reference or cloning.
1 parent 75ed342 commit 9db5c48

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)
Please sign in to comment.