]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0620.md
Re-use std::sealed::Sealed in os/linux/process.
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0620.md
1 A cast to an unsized type was attempted.
2
3 Erroneous code example:
4
5 ```compile_fail,E0620
6 let x = &[1_usize, 2] as [usize]; // error: cast to unsized type: `&[usize; 2]`
7                                   //        as `[usize]`
8 ```
9
10 In Rust, some types don't have a known size at compile-time. For example, in a
11 slice type like `[u32]`, the number of elements is not known at compile-time and
12 hence the overall size cannot be computed. As a result, such types can only be
13 manipulated through a reference (e.g., `&T` or `&mut T`) or other pointer-type
14 (e.g., `Box` or `Rc`). Try casting to a reference instead:
15
16 ```
17 let x = &[1_usize, 2] as &[usize]; // ok!
18 ```