diff options
| author | Veera <sveera.2001@gmail.com> | 2023-12-20 20:35:53 -0500 |
|---|---|---|
| committer | Veera <sveera.2001@gmail.com> | 2023-12-20 20:50:32 -0500 |
| commit | e6e195e27e6d5d12a135e4a40472c253bd63a77f (patch) | |
| tree | ad07e145b6f6236c447c099527726e738eacd39e /tests/ui/cast | |
| parent | 5ac4c8a63ee305742071ac6dd11817f7c24adce2 (diff) | |
| download | rust-e6e195e27e6d5d12a135e4a40472c253bd63a77f.tar.gz rust-e6e195e27e6d5d12a135e4a40472c253bd63a77f.zip | |
fix: diagnostic for casting reference to slice
fixes: #118790
Diffstat (limited to 'tests/ui/cast')
| -rw-r--r-- | tests/ui/cast/cast-to-slice.rs | 8 | ||||
| -rw-r--r-- | tests/ui/cast/cast-to-slice.stderr | 19 |
2 files changed, 27 insertions, 0 deletions
diff --git a/tests/ui/cast/cast-to-slice.rs b/tests/ui/cast/cast-to-slice.rs new file mode 100644 index 00000000000..a6c784a3d47 --- /dev/null +++ b/tests/ui/cast/cast-to-slice.rs @@ -0,0 +1,8 @@ +fn main() { + "example".as_bytes() as [char]; + //~^ ERROR cast to unsized type + + let arr: &[u8] = &[0, 2, 3]; + arr as [char]; + //~^ ERROR cast to unsized type +} diff --git a/tests/ui/cast/cast-to-slice.stderr b/tests/ui/cast/cast-to-slice.stderr new file mode 100644 index 00000000000..340c9c48859 --- /dev/null +++ b/tests/ui/cast/cast-to-slice.stderr @@ -0,0 +1,19 @@ +error[E0620]: cast to unsized type: `&[u8]` as `[char]` + --> $DIR/cast-to-slice.rs:2:5 + | +LL | "example".as_bytes() as [char]; + | ^^^^^^^^^^^^^^^^^^^^^^^^------ + | | + | help: try casting to a reference instead: `&[char]` + +error[E0620]: cast to unsized type: `&[u8]` as `[char]` + --> $DIR/cast-to-slice.rs:6:5 + | +LL | arr as [char]; + | ^^^^^^^------ + | | + | help: try casting to a reference instead: `&[char]` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0620`. |
