Skip to content

[ICE] internal error in match_branches on unicode range pattern #141378

New issue

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

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

Already on GitHub? Sign in to your account

Closed
giantpand2000 opened this issue May 22, 2025 · 4 comments · Fixed by #141494
Closed

[ICE] internal error in match_branches on unicode range pattern #141378

giantpand2000 opened this issue May 22, 2025 · 4 comments · Fixed by #141494
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. S-has-bisection Status: A bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@giantpand2000
Copy link

giantpand2000 commented May 22, 2025

Code

fn main() {
    let c = std::hint::black_box('c');
    let r = match c {
        '\0'..='亹' | '亻'..='及' | '双'..='\u{10ffff}' => 1usize,
        '友' => 2usize,
        '人' => 3usize,
    };
    println!("{r}");
}

Meta

rustc --version --verbose:

rustc 1.87.0 (17067e9ac 2025-05-09) running on x86_64-unknown-linux-gnu

Error output

thread 'rustc' panicked at compiler/rustc_mir_transform/src/match_branches.rs:297:14:
internal error: entered unreachable code: invalid int
stack backtrace:
   0:     0x7a0487e8a3c3 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hc04c8f544ab24d66
   1:     0x7a0488605b51 - core::fmt::write::hfe57b7174b7d8eab
   2:     0x7a0489a8e011 - std::io::Write::write_fmt::h154385efa8565236
   3:     0x7a0487e8a222 - std::sys::backtrace::BacktraceLock::print::h0c8f24e22f5873a8
   4:     0x7a0487e8cada - std::panicking::default_hook::{{closure}}::hd07d57e6a602c8e4
   5:     0x7a0487e8c65f - std::panicking::default_hook::h63d12f7d95bd91ed
   6:     0x7a0486ef0450 - std[ab9b65b5f5dd2f44]::panicking::update_hook::<alloc[4810a64b00f2b3b7]::boxed::Box<rustc_driver_impl[ddaea9a5059e4009]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7a0487e8d353 - std::panicking::rust_panic_with_hook::h33b18b24045abff4
   8:     0x7a0487e8d016 - std::panicking::begin_panic_handler::{{closure}}::hf8313cc2fd0126bc
   9:     0x7a0487e8a899 - std::sys::backtrace::__rust_end_short_backtrace::h57fe07c8aea5c98a
  10:     0x7a0487e8cd0d - __rustc[95feac21a9532783]::rust_begin_unwind
  11:     0x7a0484894960 - core::panicking::panic_fmt::hd54fb667be51beea
  12:     0x7a048a431d02 - rustc_mir_transform[3f8bf91e0e7bcf96]::match_branches::can_cast::<u128>.cold
  13:     0x7a04890e7299 - <rustc_mir_transform[3f8bf91e0e7bcf96]::match_branches::MatchBranchSimplification as rustc_mir_transform[3f8bf91e0e7bcf96]::pass_manager::MirPass>::run_pass
  14:     0x7a04886039fb - rustc_mir_transform[3f8bf91e0e7bcf96]::pass_manager::run_passes_inner
  15:     0x7a0488ff63e2 - rustc_mir_transform[3f8bf91e0e7bcf96]::optimized_mir
  16:     0x7a0488ff59cb - rustc_query_impl[9eb226868f218d86]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9eb226868f218d86]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f5c565be837cd477]::query::erase::Erased<[u8; 8usize]>>
  17:     0x7a04886224af - rustc_query_system[719b00724ab1874c]::query::plumbing::try_execute_query::<rustc_query_impl[9eb226868f218d86]::DynamicConfig<rustc_query_system[719b00724ab1874c]::query::caches::DefIdCache<rustc_middle[f5c565be837cd477]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9eb226868f218d86]::plumbing::QueryCtxt, false>
  18:     0x7a04886218dd - rustc_query_impl[9eb226868f218d86]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  19:     0x7a04890cb8f2 - <rustc_middle[f5c565be837cd477]::ty::context::TyCtxt>::instance_mir
  20:     0x7a0485639277 - rustc_monomorphize[4f6dde2ed994733c]::mono_checks::check_mono_item
  21:     0x7a04890fcbfe - rustc_query_impl[9eb226868f218d86]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9eb226868f218d86]::query_impl::check_mono_item::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f5c565be837cd477]::query::erase::Erased<[u8; 0usize]>>
  22:     0x7a04890fcf1d - rustc_query_system[719b00724ab1874c]::query::plumbing::try_execute_query::<rustc_query_impl[9eb226868f218d86]::DynamicConfig<rustc_query_system[719b00724ab1874c]::query::caches::DefaultCache<rustc_middle[f5c565be837cd477]::ty::instance::Instance, rustc_middle[f5c565be837cd477]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[9eb226868f218d86]::plumbing::QueryCtxt, false>
  23:     0x7a04890fcbcd - rustc_query_impl[9eb226868f218d86]::query_impl::check_mono_item::get_query_non_incr::__rust_end_short_backtrace
  24:     0x7a0485642bff - rustc_monomorphize[4f6dde2ed994733c]::collector::items_of_instance
  25:     0x7a0488ea6f32 - rustc_query_impl[9eb226868f218d86]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9eb226868f218d86]::query_impl::items_of_instance::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f5c565be837cd477]::query::erase::Erased<[u8; 32usize]>>
  26:     0x7a0488ea729a - rustc_query_system[719b00724ab1874c]::query::plumbing::try_execute_query::<rustc_query_impl[9eb226868f218d86]::DynamicConfig<rustc_query_system[719b00724ab1874c]::query::caches::DefaultCache<(rustc_middle[f5c565be837cd477]::ty::instance::Instance, rustc_middle[f5c565be837cd477]::mir::mono::CollectionMode), rustc_middle[f5c565be837cd477]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[9eb226868f218d86]::plumbing::QueryCtxt, false>
  27:     0x7a0488ea6eab - rustc_query_impl[9eb226868f218d86]::query_impl::items_of_instance::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7a0488ea8f6a - rustc_monomorphize[4f6dde2ed994733c]::collector::collect_items_rec::{closure#0}
  29:     0x7a0488ea9e7b - rustc_monomorphize[4f6dde2ed994733c]::collector::collect_items_rec
  30:     0x7a0488c16765 - rustc_monomorphize[4f6dde2ed994733c]::partitioning::collect_and_partition_mono_items
  31:     0x7a04898d8da6 - rustc_query_impl[9eb226868f218d86]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9eb226868f218d86]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f5c565be837cd477]::query::erase::Erased<[u8; 40usize]>>
  32:     0x7a04898d8d8b - <rustc_query_impl[9eb226868f218d86]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[6e25f1b983e4a449]::ops::function::FnOnce<(rustc_middle[f5c565be837cd477]::ty::context::TyCtxt, ())>>::call_once
  33:     0x7a04898d88b4 - rustc_query_system[719b00724ab1874c]::query::plumbing::try_execute_query::<rustc_query_impl[9eb226868f218d86]::DynamicConfig<rustc_query_system[719b00724ab1874c]::query::caches::SingleCache<rustc_middle[f5c565be837cd477]::query::erase::Erased<[u8; 40usize]>>, false, false, false>, rustc_query_impl[9eb226868f218d86]::plumbing::QueryCtxt, false>
  34:     0x7a04898d8644 - rustc_query_impl[9eb226868f218d86]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  35:     0x7a04897935e0 - <rustc_codegen_llvm[dedd2c942a2348b0]::LlvmCodegenBackend as rustc_codegen_ssa[22cc9466fca14ff3]::traits::backend::CodegenBackend>::codegen_crate
  36:     0x7a0489734895 - <rustc_interface[4f8e933b45f54331]::queries::Linker>::codegen_and_build_linker
  37:     0x7a0489731f28 - rustc_interface[4f8e933b45f54331]::passes::create_and_enter_global_ctxt::<core[6e25f1b983e4a449]::option::Option<rustc_interface[4f8e933b45f54331]::queries::Linker>, rustc_driver_impl[ddaea9a5059e4009]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  38:     0x7a0489723eaa - rustc_interface[4f8e933b45f54331]::interface::run_compiler::<(), rustc_driver_impl[ddaea9a5059e4009]::run_compiler::{closure#0}>::{closure#1}
  39:     0x7a0489564f08 - std[ab9b65b5f5dd2f44]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[4f8e933b45f54331]::util::run_in_thread_with_globals<rustc_interface[4f8e933b45f54331]::util::run_in_thread_pool_with_globals<rustc_interface[4f8e933b45f54331]::interface::run_compiler<(), rustc_driver_impl[ddaea9a5059e4009]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  40:     0x7a04895657f4 - <<std[ab9b65b5f5dd2f44]::thread::Builder>::spawn_unchecked_<rustc_interface[4f8e933b45f54331]::util::run_in_thread_with_globals<rustc_interface[4f8e933b45f54331]::util::run_in_thread_pool_with_globals<rustc_interface[4f8e933b45f54331]::interface::run_compiler<(), rustc_driver_impl[ddaea9a5059e4009]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[6e25f1b983e4a449]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41:     0x7a0489566bf7 - std::sys::pal::unix::thread::Thread::new::thread_start::h2717d4f9aca577e6
  42:     0x7a048348aaa4 - <unknown>
  43:     0x7a0483517a34 - clone
  44:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.87.0 (17067e9ac 2025-05-09) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [optimized_mir] optimizing MIR for `main`
#1 [check_mono_item] monomorphization-time checking
... and 2 other queries... use `env RUST_BACKTRACE=1` to see the full query stack
error: could not compile `playground` (bin "playground")
Backtrace

Compiling playground v0.0.1 (/playground)

thread 'rustc' panicked at compiler/rustc_mir_transform/src/match_branches.rs:297:14:
internal error: entered unreachable code: invalid int
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: rustc_mir_transform::match_branches::can_cast::<u128>.cold
   3: <rustc_mir_transform::match_branches::MatchBranchSimplification as rustc_mir_transform::pass_manager::MirPass>::run_pass
   4: rustc_mir_transform::pass_manager::run_passes_inner
   5: rustc_mir_transform::optimized_mir
      [... omitted 1 frame ...]
   6: <rustc_middle::ty::context::TyCtxt>::instance_mir
   7: rustc_monomorphize::mono_checks::check_mono_item
      [... omitted 1 frame ...]
   8: rustc_monomorphize::collector::items_of_instance
      [... omitted 1 frame ...]
   9: rustc_monomorphize::collector::collect_items_rec::{closure#0}
  10: rustc_monomorphize::collector::collect_items_rec
  11: rustc_monomorphize::partitioning::collect_and_partition_mono_items
      [... omitted 2 frames ...]
  12: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  13: <rustc_interface::queries::Linker>::codegen_and_build_linker
  14: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  15: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.87.0 (17067e9ac 2025-05-09) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [optimized_mir] optimizing MIR for `main`
#1 [check_mono_item] monomorphization-time checking
#2 [items_of_instance] collecting items used by `main`
#3 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: could not compile `playground` (bin "playground")

@giantpand2000 giantpand2000 added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels May 22, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 22, 2025
@cyrgani
Copy link
Contributor

cyrgani commented May 22, 2025

no need for unicode:

fn main() {
    let _a = match 'c' {
        '\0'..='a' | 'c'..='e' | 'g'..=char::MAX => 1,
        'b' => 3,
        'f' => 2,
    };
}

@cyrgani
Copy link
Contributor

cyrgani commented May 22, 2025

this used to compile in 1.81, ICE since 1.82
@rustbot label regression-from-stable-to-stable S-has-mcve E-needs-bisection

@rustbot rustbot added E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc regression-from-stable-to-stable Performance or correctness regression from one stable version to another. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels May 22, 2025
@matthiaskrgr
Copy link
Member

nightly-2024-08-04 , probably #127324 cc @dianqk

@dianqk dianqk self-assigned this May 22, 2025
@apiraino
Copy link
Contributor

Assigning priority (discussion on Zulip).

@rustbot label -I-prioritize +P-medium -e-needs-bisection

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc labels May 22, 2025
@apiraino apiraino removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 22, 2025
@jieyouxu jieyouxu added the S-has-bisection Status: A bisection has been found for this issue label May 22, 2025
workingjubilee added a commit to workingjubilee/rustc that referenced this issue May 30, 2025
…iser

mir-opt: Do not transform non-int type in match_branches

Fixes rust-lang#141378.

r? mir-opt
@bors bors closed this as completed in 3846f2f May 31, 2025
rust-timer added a commit that referenced this issue May 31, 2025
Rollup merge of #141494 - dianqk:match-br-non-int, r=wesleywiser

mir-opt: Do not transform non-int type in match_branches

Fixes #141378.

r? mir-opt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. S-has-bisection Status: A bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants