From 9db5c483ab50d70db6381f70c17711e2e472c0d3 Mon Sep 17 00:00:00 2001 From: mbartlett21 <29034492+mbartlett21@users.noreply.github.com> Date: Tue, 22 Jun 2021 22:24:46 +1000 Subject: [PATCH] Add destructuring example of E0508 This adds an example that destructures the array to move the value, instead of taking a reference or cloning. --- compiler/rustc_error_codes/src/error_codes/E0508.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/compiler/rustc_error_codes/src/error_codes/E0508.md b/compiler/rustc_error_codes/src/error_codes/E0508.md index 33572fca6a3e8..91865907bf271 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; +} +```