Closed
Description
Given the following code: playground link
pub fn u32_as_char(x: u32) -> char {
(x as u32) as char
}
The current output is:
error[[E0604]](https://doc.rust-lang.org/stable/error-index.html#E0604): only `u8` can be cast as `char`, not `u32`
--> src/lib.rs:3:5
|
3 | (x as u32) as char
| ^^^^^^^^^^^^^^^^^^ invalid cast
|
help: try `char::from_u32` instead
--> src/lib.rs:3:5
|
3 | (x as u32) as char
| ^^^^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0604`.
Ideally the output should look like:
error[[E0604]](https://doc.rust-lang.org/stable/error-index.html#E0604): only `u8` can be cast as `char`, not `u32`
--> src/lib.rs:3:5
|
3 | (x as u32) as char
| ^^^^^^^^^^^^^^^^^^ invalid cast
|
help: try `char::from_u32` instead
--> src/lib.rs:3:5
|
3 | char::from_u32(x as u32)
| ^^^^^^^^^^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0604`.