@@ -967,6 +967,50 @@ You can find more information about borrowing in the rust-book:
967967http://doc.rust-lang.org/stable/book/references-and-borrowing.html
968968"## ,
969969
970+ E0508 : r##"
971+ A value was moved out of a non-copy fixed-size array.
972+
973+ Example of erroneous code:
974+
975+ ```compile_fail
976+ struct NonCopy;
977+
978+ fn main() {
979+ let array = [NonCopy; 1];
980+ let _value = array[0]; // error: cannot move out of type `[NonCopy; 1]`,
981+ // a non-copy fixed-size array
982+ }
983+ ```
984+
985+ The first element was moved out of the array, but this is not
986+ possible because `NonCopy` does not implement the `Copy` trait.
987+
988+ Consider borrowing the element instead of moving it:
989+
990+ ```
991+ struct NonCopy;
992+
993+ fn main() {
994+ let array = [NonCopy; 1];
995+ let _value = &array[0]; // Borrowing is allowed, unlike moving.
996+ }
997+ ```
998+
999+ Alternatively, if your type implements `Clone` and you need to own the value,
1000+ consider borrowing and then cloning:
1001+
1002+ ```
1003+ #[derive(Clone)]
1004+ struct NonCopy;
1005+
1006+ fn main() {
1007+ let array = [NonCopy; 1];
1008+ // Now you can clone the array element.
1009+ let _value = array[0].clone();
1010+ }
1011+ ```
1012+ "## ,
1013+
9701014E0509 : r##"
9711015This error occurs when an attempt is made to move out of a value whose type
9721016implements the `Drop` trait.
@@ -1067,6 +1111,5 @@ fn main() {
10671111register_diagnostics ! {
10681112 E0385 , // {} in an aliasable location
10691113 E0388 , // {} in a static location
1070- E0508 , // cannot move out of type `..`, a non-copy fixed-size array
10711114 E0524 , // two closures require unique access to `..` at the same time
10721115}
0 commit comments