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