Fix error reporting for multibyte characters in byte string literal by tapanprakasht · Pull Request #139362 · rust-lang/rust (original) (raw)
I think there may also need to be consideration of the situation in the origin code, where it's possible that users may want to use single bytes, so we can explicitly state that the suggested value is a single byte value, not a UTF-8 encoding.
So, we could add this suggestion above if mode == Mode::Byte {
such as below.
if (c as u32) <= 0xFF && mode != Mode::RawByteStr {
err.span_suggestion(
span,
format!(
"if you meant to use the byte with hex value {:#04X} (note: this is not the Unicode code point for {c:?})",
c as u32
),
format!("\\x{:02X}", c as u32),
Applicability::MaybeIncorrect,
);
}