Change:
Given the following code: The current output is: This is not very clear. There are two pieces of background information the user needs here: s are Unicode scalar values, which are any integer value from 0 to 0xD7FF and 0xE000 to 0x10FFFF. Only u8 can be statically guaranteed to meet this requirement so only u8 can be cast to char. is probably what the user wants, if they are interested in non-ASCII values. The user is directed to further information available at and , neither of which explains either of those two points. <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
I think a good improvement would be to a) Add more detail about this to b) Add a to this error that suggests are you interested in working on one or both of those? :)
claim
While I was reading the docs I noticed a minor error in : This isn't true; a USV is a Code Point within either of two ranges, not one. It's also a bit cagey about what the ranges are numerically; I don't know if this is intentional. Personally I would re-write it to the below: Would I put that in the same PR (as they're both documentation) or a new issue?
A new PR would be better.

Discussion:
0u32 as char; // error: only `u8` can be cast as `char`, not `u32` ``` <del> As the error message indicates, only `u8` can be cast into `char`. Example: </del> <ins> `char` is a Unicode Scalar Value, an integer value from 0 to 0xD7FF and 0xE000 to 0x10FFFF. (The gap is for surrogate pairs.) Only `u8` always fits in those ranges so only `u8` may be cast to `char`. To allow larger values, use `char::from_u32`, which checks the value is valid. </ins> ``` <del> let c = 86u8 as char; // ok! assert_eq!(c, 'V'); </del> <ins> assert_eq!(86u8 as char, 'V'); // ok! assert_eq!(char::from_u32(0x3B1), Some('α')); // ok! assert_eq!(char::from_u32(0xD800), None); // not a USV. </ins> ``` For more information about casts, take a look at the Type cast section in

err.emit(); } CastError::CastToChar => { <del> type_error_struct!( </del> <ins> let mut err = type_error_struct!( </ins> fcx.tcx.sess, self.span, self.expr_ty, E0604, "only `u8` can be cast as `char`, not `{}`", self.expr_ty <del> ) .span_label(self.span, "invalid cast") .emit(); </del> <ins> ); err.span_label(self.span, "invalid cast"); if self.expr_ty.is_numeric() { err.span_help( self.span, if self.expr_ty == fcx.tcx.types.i8 { "try casting from `u8` instead" } else if self.expr_ty == fcx.tcx.types.u32 { "try `char::from_u32` instead" } else { "try `char::from_u32` instead (via a `u32`)" }, ); } err.emit(); </ins> } CastError::NonScalar => { let mut err = type_error_struct!(

| LL |     : [u32; 5i8 as char as usize] |             ^^^^^^^^^^^ invalid cast <ins> | help: try casting from `u8` instead --> $DIR/const-eval-overflow-4b.rs:22:13 | LL |     : [u32; 5i8 as char as usize] |             ^^^^^^^^^^^ </ins> error: aborting due to 3 previous errors

| LL |     1u32 as char; |     ^^^^^^^^^^^^ invalid cast <ins> | help: try `char::from_u32` instead --> $DIR/E0604.rs:2:5 | LL |     1u32 as char; |     ^^^^^^^^^^^^ </ins> error: aborting due to previous error

| LL |     0u32 as char; |     ^^^^^^^^^^^^ invalid cast <ins> | help: try `char::from_u32` instead --> $DIR/error-festival.rs:25:5 | LL |     0u32 as char; |     ^^^^^^^^^^^^ </ins> error[E0605]: non-primitive cast: `u8` as `Vec<u8>` --> $DIR/error-festival.rs:29:5

| LL |     let _ = 0x61u32 as char; |             ^^^^^^^^^^^^^^^ invalid cast <ins> | help: try `char::from_u32` instead --> $DIR/cast-rfc0401.rs:41:13 | LL |     let _ = 0x61u32 as char; |             ^^^^^^^^^^^^^^^ </ins> error[E0606]: casting `bool` as `f32` is invalid --> $DIR/cast-rfc0401.rs:43:13