Rollup merge of #91939 - GKFX:feature-91866, r=cjgillot

Clarify error on casting larger integers to char

Closes #91836 with changes to E0604.md and a `span_help`.
This commit is contained in:
Matthias Krüger 2022-02-06 04:13:29 +01:00 committed by GitHub
commit 58bfe72f52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 7 deletions

View file

@ -17,6 +17,12 @@ error[E0604]: only `u8` can be cast as `char`, not `i8`
|
LL | : [u32; 5i8 as char as usize]
| ^^^^^^^^^^^ invalid cast
|
help: try casting from `u8` instead
--> $DIR/const-eval-overflow-4b.rs:22:13
|
LL | : [u32; 5i8 as char as usize]
| ^^^^^^^^^^^
error: aborting due to 3 previous errors

View file

@ -3,6 +3,12 @@ error[E0604]: only `u8` can be cast as `char`, not `u32`
|
LL | 1u32 as char;
| ^^^^^^^^^^^^ invalid cast
|
help: try `char::from_u32` instead
--> $DIR/E0604.rs:2:5
|
LL | 1u32 as char;
| ^^^^^^^^^^^^
error: aborting due to previous error

View file

@ -58,6 +58,12 @@ error[E0604]: only `u8` can be cast as `char`, not `u32`
|
LL | 0u32 as char;
| ^^^^^^^^^^^^ invalid cast
|
help: try `char::from_u32` instead
--> $DIR/error-festival.rs:25:5
|
LL | 0u32 as char;
| ^^^^^^^^^^^^
error[E0605]: non-primitive cast: `u8` as `Vec<u8>`
--> $DIR/error-festival.rs:29:5

View file

@ -99,6 +99,12 @@ error[E0604]: only `u8` can be cast as `char`, not `u32`
|
LL | let _ = 0x61u32 as char;
| ^^^^^^^^^^^^^^^ invalid cast
|
help: try `char::from_u32` instead
--> $DIR/cast-rfc0401.rs:41:13
|
LL | let _ = 0x61u32 as char;
| ^^^^^^^^^^^^^^^
error[E0606]: casting `bool` as `f32` is invalid
--> $DIR/cast-rfc0401.rs:43:13