Skip to content

Out-of-range \x escapes should suggest alternatives #148917

Closed

Description

@scottmcm

Code

dbg!('\xFF');

Current output

error: out of range hex escape
 --> src/main.rs:2:11
  |
2 |     dbg!('\xFF');
  |           ^^^^ must be a character in the range [\x00-\x7f]

Desired output

error: out of range hex escape
 --> src/main.rs:2:11
  |
2 |     dbg!('\xFF');
  |           ^^^^ must be a character in the range [\x00-\x7f]
  |
  | hint: Perhaps you want `b'\xFF'` for a single byte with that value or `'\u{FF}'` for that Unicode character.

Rationale and extra context

No response

Other cases

Rust Version

Build using the Nightly version: 1.93.0-nightly

(2025-11-12 01867557cd7dbe256a03)

Anything else?

Repro: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=78af4a05d6f14cb870fd0bddbe058dbd

Inspired by #t-lang > 7-bit escapes.

cc rust-lang/rfcs#3349

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Nov 13, 2025
  2. self-assigned this
    on Nov 14, 2025
  3. added a commit that references this issue on Nov 24, 2025
    ade1581
  4. added a commit that references this issue on Nov 24, 2025
    93d7e18
  5. added a commit that references this issue on Nov 25, 2025
    ff11e77
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions