Skip to content

char::from_u32_unchecked panics at runtime in 1.78.0 but works in 1.77.1 #124922

Closed
@bvanjoi

Description

@bvanjoi

Code

I tried this code:

fn main() {
    let ch = unsafe {
        std::char::from_u32_unchecked(55357)
    };
    dbg!(ch);
}

I expected to see this happen: run success.

Instead, this happened: panic at runtime and report "invalid value for char"

Version it worked on

It most recently worked on: 1.77.1

Version with regression

rustc --version --verbose:

rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: aarch64-apple-darwin
release: 1.78.0
LLVM version: 18.1.2

Backtrace

Backtrace

thread 'main' panicked at library/core/src/panicking.rs:156:5:
unsafe precondition(s) violated: invalid value for `char`
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_nounwind_fmt::runtime
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:110:18
   2: core::panicking::panic_nounwind_fmt
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:123:9
   3: core::panicking::panic_nounwind
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:156:5
   4: core::char::convert::from_u32_unchecked::precondition_check
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/intrinsics.rs:2799:21
   5: core::char::convert::from_u32_unchecked
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/char/convert.rs:28:9
   6: core::char::from_u32_unchecked
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/char/mod.rs:131:14
   7: rust_local_test::main
             at ./src/main.rs:29:9
   8: core::ops::function::FnOnce::call_once
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/ops/function.rs:250:5

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions