Skip to content

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

@scottmcm

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

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