Skip to content

overflowing_literals suggests invalid unicode character escape #143597

Closed
@matthiaskrgr

Description

@matthiaskrgr

Using the following flags

--force-warn overflowing_literals

this code:

fn main() {
    const XYZ: char = 0xEF8888 as char;
    println!("{}", XYZ);
}

caused the following diagnostics:

    Checking _a v0.1.0 (/tmp/icemaker_global_tempdir.9yw7ni8AzjBW/icemaker_clippyfix_tempdir.Hb8kKG9SiLPB/_a)
warning: only `u8` can be cast into `char`
 --> src/main.rs:2:23
  |
2 |     const XYZ: char = 0xEF8888 as char;
  |                       ^^^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{EF8888}'`
  |
  = note: requested on the command line with `--force-warn overflowing-literals`

warning: `_a` (bin "_a") generated 1 warning (run `cargo clippy --fix --bin "_a"` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s

However after applying these diagnostics, the resulting code:

fn main() {
    const XYZ: char = '\u{EF8888}';
    println!("{}", XYZ);
}

no longer compiled:

    Checking _a v0.1.0 (/tmp/icemaker_global_tempdir.9yw7ni8AzjBW/icemaker_clippyfix_tempdir.Hb8kKG9SiLPB/_a)
error: invalid unicode character escape
 --> src/main.rs:2:24
  |
2 |     const XYZ: char = '\u{EF8888}';
  |                        ^^^^^^^^^^ invalid escape
  |
  = help: unicode escape must be at most 10FFFF

error: could not compile `_a` (bin "_a") due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `_a` (bin "_a" test) due to 1 previous error

Version:

rustc 1.90.0-nightly (25cf7d13c 2025-07-07)
binary: rustc
commit-hash: 25cf7d13c960a3ac47d1424ca354077efb6946ff
commit-date: 2025-07-07
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.L-overflowing_literalsLint: overflowing_literalsT-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