diff options
| author | mbartlett21 <29034492+mbartlett21@users.noreply.github.com> | 2021-06-22 22:24:46 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-22 22:24:46 +1000 |
| commit | 9db5c483ab50d70db6381f70c17711e2e472c0d3 (patch) | |
| tree | 6c8d23e13e3a48d358321af479abf709941c44a5 /compiler/rustc_error_codes/src | |
| parent | 75ed34223adb02c7bbfa5ae5e62c48952ff29914 (diff) | |
| download | rust-9db5c483ab50d70db6381f70c17711e2e472c0d3.tar.gz rust-9db5c483ab50d70db6381f70c17711e2e472c0d3.zip | |
Add destructuring example of E0508
This adds an example that destructures the array to move the value, instead of taking a reference or cloning.
Diffstat (limited to 'compiler/rustc_error_codes/src')
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0508.md | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0508.md b/compiler/rustc_error_codes/src/error_codes/E0508.md index 33572fca6a3..91865907bf2 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0508.md +++ b/compiler/rustc_error_codes/src/error_codes/E0508.md @@ -39,3 +39,16 @@ fn main() { let _value = array[0].clone(); } ``` + +If you really want to move the value out, you can use a destructuring array +pattern to move it: + +``` +struct NonCopy; + +fn main() { + let array = [NonCopy; 1]; + // Destructuring the array + let [_value] = array; +} +``` |
