unicode code point suggestion for non-ASCII character in byte string literal is incorrect
Open
@tapanprakasht is already working on this.
Since Apr 4, 2025.
A-diagnostics
A-suggestion-diagnostics
A-Unicode
D-invalid-suggestion
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
If you try to compile this:
fn main() {
let bytes = b"ñ";
}
You'll get:
error: non-ASCII character in byte string literal
--> src/main.rs:2:19
|
2 | let bytes = b"ñ";
| ^ must be ASCII
|
help: if you meant to use the unicode code point for 'ñ', use a \xHH escape
|
2 | let bytes = b"\xF1";
| ~~~~
This is an unhelpful suggestion, because that's not a correct unicode encoding for 'ñ' (in utf-8, it would be "\xC3\xB1", and in utf-16 it would be "\x00\xF1").
Meta
rustc --version --verbose: This reproduces on https://play.rust-lang.org with both stable and nightly (although the output is a bit different on nightly)
Backtrace
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.