From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_error_codes/src/error_codes/E0620.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 compiler/rustc_error_codes/src/error_codes/E0620.md (limited to 'compiler/rustc_error_codes/src/error_codes/E0620.md') diff --git a/compiler/rustc_error_codes/src/error_codes/E0620.md b/compiler/rustc_error_codes/src/error_codes/E0620.md new file mode 100644 index 000000000..f8e442807 --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0620.md @@ -0,0 +1,18 @@ +A cast to an unsized type was attempted. + +Erroneous code example: + +```compile_fail,E0620 +let x = &[1_usize, 2] as [usize]; // error: cast to unsized type: `&[usize; 2]` + // as `[usize]` +``` + +In Rust, some types don't have a known size at compile-time. For example, in a +slice type like `[u32]`, the number of elements is not known at compile-time and +hence the overall size cannot be computed. As a result, such types can only be +manipulated through a reference (e.g., `&T` or `&mut T`) or other pointer-type +(e.g., `Box` or `Rc`). Try casting to a reference instead: + +``` +let x = &[1_usize, 2] as &[usize]; // ok! +``` -- cgit v1.2.3