rust-lang / rust-lang/rust

unicode code point suggestion for non-ASCII character in byte string literal is incorrect

Open
#139,226 1 comment 0 reactions 1 assignee View on GitHub

@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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.