]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0161.md
Auto merge of #66396 - smmalis37:pythontest, r=alexcrichton
[rust.git] / src / librustc_error_codes / error_codes / E0161.md
1 A value was moved. However, its size was not known at compile time, and only
2 values of a known size can be moved.
3
4 Erroneous code example:
5
6 ```compile_fail,E0161
7 #![feature(box_syntax)]
8
9 fn main() {
10     let array: &[isize] = &[1, 2, 3];
11     let _x: Box<[isize]> = box *array;
12     // error: cannot move a value of type [isize]: the size of [isize] cannot
13     //        be statically determined
14 }
15 ```
16
17 In Rust, you can only move a value when its size is known at compile time.
18
19 To work around this restriction, consider "hiding" the value behind a reference:
20 either `&x` or `&mut x`. Since a reference has a fixed size, this lets you move
21 it around as usual. Example:
22
23 ```
24 #![feature(box_syntax)]
25
26 fn main() {
27     let array: &[isize] = &[1, 2, 3];
28     let _x: Box<&[isize]> = box array; // ok!
29 }
30 ```