Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mozkeeler opened this issue Apr 1, 2025 · 1 comment · May be fixed by #139362
Open

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

mozkeeler opened this issue Apr 1, 2025 · 1 comment · May be fixed by #139362
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` A-Unicode Area: Unicode D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mozkeeler
Copy link

mozkeeler commented Apr 1, 2025

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

@mozkeeler mozkeeler added the C-bug Category: This is a bug. label Apr 1, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 1, 2025
@lolbinarycat lolbinarycat added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 1, 2025
@fmease fmease added A-Unicode Area: Unicode D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` and removed C-bug Category: This is a bug. labels Apr 2, 2025
@tapanprakasht
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` A-Unicode Area: Unicode D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants