Skip to content
New issue

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

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

Already on GitHub? # to your account

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

Closed
bvanjoi opened this issue May 9, 2024 · 2 comments
Closed
Labels
C-bug Category: This is a bug.

Comments

@bvanjoi
Copy link
Contributor

bvanjoi commented May 9, 2024

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

@bvanjoi bvanjoi added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels May 9, 2024
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 9, 2024
@Urgau
Copy link
Member

Urgau commented May 9, 2024

I think this is expected, it was in the compatibility notes of Rust 1.78:

Compatibility Notes

@bvanjoi
Copy link
Contributor Author

bvanjoi commented May 9, 2024

@Urgau Thanks for the quick reply! I think we can close this issue.

@bvanjoi bvanjoi closed this as completed May 9, 2024
@jieyouxu jieyouxu removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-untriaged Untriaged performance or correctness regression. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 9, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants