rust-lang / rust-lang/rust

ICE: debuginfo: unexpected type in type_di_node(): pattern_type!(i8 is 1..=2)

Open
#145,514 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-debuginfo A-patterns C-bug F-pattern_types I-ICE T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
#![feature(pattern_types, pattern_type_macro, pattern_type_range_trait)]
use std::io::{Write, stderr};
use std::pat;

type SmallInt = pat::pattern_type!(i8 is 1..=2);
fn main() {
    let s: SmallInt = unsafe { core::mem::transmute(1i8) };
    let _ = stderr().lock().write_fmt(format_args!("{}\n", unsafe {
        core::mem::transmute::<_, i8>(s)
    }));
}
Meta

rustc --version --verbose:

rustc 1.91.0-nightly (cd7cbe818 2025-08-15)
binary: rustc
commit-hash: cd7cbe818e4a66d46fe2df993d1b8518eba8a5cd
commit-date: 2025-08-15
host: x86_64-unknown-linux-gnu
release: 1.91.0-nightly
LLVM version: 21.1.0
Error output
error: internal compiler error: compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs:466:14: debuginfo: unexpected type in type_di_node(): pattern_type!(i8 is 1..=2)


thread 'rustc' (4925) panicked at compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs:466:14:
Box<dyn Any>
Backtrace

   0:     0x7f9b4800a183 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hb7d54e90572dcd74
   1:     0x7f9b48801a7c - core::fmt::write::h23be9617f50201fc
   2:     0x7f9b47ff49c3 - std::io::Write::write_fmt::h351b8ef2fbc321e2
   3:     0x7f9b48009dd2 - std::sys::backtrace::BacktraceLock::print::hebefa2de1050d28a
   4:     0x7f9b47fec600 - std::panicking::default_hook::{{closure}}::hcf87941fd5ee572d
   5:     0x7f9b47fec12c - std::panicking::default_hook::h727f8b8141944d56
   6:     0x7f9b4705ccc5 - std[220d04c6371a334c]::panicking::update_hook::<alloc[fbc066ed6891e5d8]::boxed::Box<rustc_driver_impl[a29ea5a24b8f2ec1]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7f9b47fecc85 - std::panicking::panic_with_hook::hd0a9fb167f5001f7
   8:     0x7f9b47096561 - std[220d04c6371a334c]::panicking::begin_panic::<rustc_errors[371fe44f8f203912]::ExplicitBug>::{closure#0}
   9:     0x7f9b47096536 - std[220d04c6371a334c]::sys::backtrace::__rust_end_short_backtrace::<std[220d04c6371a334c]::panicking::begin_panic<rustc_errors[371fe44f8f203912]::ExplicitBug>::{closure#0}, !>
  10:     0x7f9b470946f0 - std[220d04c6371a334c]::panicking::begin_panic::<rustc_errors[371fe44f8f203912]::ExplicitBug>
  11:     0x7f9b47080b01 - <rustc_errors[371fe44f8f203912]::diagnostic::BugAbort as rustc_errors[371fe44f8f203912]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7f9b4769010a - rustc_middle[2c60d99a48b88058]::util::bug::opt_span_bug_fmt::<rustc_span[cefc81db55162a98]::span_encoding::Span>::{closure#0}
  13:     0x7f9b4769004a - rustc_middle[2c60d99a48b88058]::ty::context::tls::with_opt::<rustc_middle[2c60d99a48b88058]::util::bug::opt_span_bug_fmt<rustc_span[cefc81db55162a98]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7f9b4769001b - rustc_middle[2c60d99a48b88058]::ty::context::tls::with_context_opt::<rustc_middle[2c60d99a48b88058]::ty::context::tls::with_opt<rustc_middle[2c60d99a48b88058]::util::bug::opt_span_bug_fmt<rustc_span[cefc81db55162a98]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7f9b446db5c0 - rustc_middle[2c60d99a48b88058]::util::bug::bug_fmt
  16:     0x7f9b48ff45e6 - rustc_codegen_llvm[62b9691424515867]::debuginfo::metadata::type_di_node
  17:     0x7f9b48ff1d16 - <rustc_codegen_llvm[62b9691424515867]::context::GenericCx<rustc_codegen_llvm[62b9691424515867]::context::FullCx> as rustc_codegen_ssa[7c42cfa78ee9ce8a]::traits::debuginfo::DebugInfoCodegenMethods>::create_dbg_var
  18:     0x7f9b49c39636 - rustc_codegen_ssa[7c42cfa78ee9ce8a]::mir::codegen_mir::<rustc_codegen_llvm[62b9691424515867]::builder::GenericBuilder<rustc_codegen_llvm[62b9691424515867]::context::FullCx>>
  19:     0x7f9b48988927 - rustc_codegen_llvm[62b9691424515867]::base::compile_codegen_unit::module_codegen
  20:     0x7f9b49be10fd - <rustc_codegen_llvm[62b9691424515867]::LlvmCodegenBackend as rustc_codegen_ssa[7c42cfa78ee9ce8a]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  21:     0x7f9b49bdedb7 - <rustc_codegen_llvm[62b9691424515867]::LlvmCodegenBackend as rustc_codegen_ssa[7c42cfa78ee9ce8a]::traits::backend::CodegenBackend>::codegen_crate
  22:     0x7f9b498ba170 - <rustc_interface[9560d1bb3c44bdee]::queries::Linker>::codegen_and_build_linker
  23:     0x7f9b498b7cfc - rustc_interface[9560d1bb3c44bdee]::passes::create_and_enter_global_ctxt::<core[5c58642aafdad712]::option::Option<rustc_interface[9560d1bb3c44bdee]::queries::Linker>, rustc_driver_impl[a29ea5a24b8f2ec1]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  24:     0x7f9b49a84c83 - rustc_interface[9560d1bb3c44bdee]::interface::run_compiler::<(), rustc_driver_impl[a29ea5a24b8f2ec1]::run_compiler::{closure#0}>::{closure#1}
  25:     0x7f9b49965ef8 - std[220d04c6371a334c]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[9560d1bb3c44bdee]::util::run_in_thread_with_globals<rustc_interface[9560d1bb3c44bdee]::util::run_in_thread_pool_with_globals<rustc_interface[9560d1bb3c44bdee]::interface::run_compiler<(), rustc_driver_impl[a29ea5a24b8f2ec1]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  26:     0x7f9b49965bc8 - <<std[220d04c6371a334c]::thread::Builder>::spawn_unchecked_<rustc_interface[9560d1bb3c44bdee]::util::run_in_thread_with_globals<rustc_interface[9560d1bb3c44bdee]::util::run_in_thread_pool_with_globals<rustc_interface[9560d1bb3c44bdee]::interface::run_compiler<(), rustc_driver_impl[a29ea5a24b8f2ec1]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[5c58642aafdad712]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  27:     0x7f9b499618cb - std::sys::pal::unix::thread::Thread::new::thread_start::h07bc13a8346182c2
  28:     0x7f9b432bddf4 - <unknown>
  29:     0x7f9b4332d7cc - <unknown>
  30:                0x0 - <unknown

Where the bug occurs in the compiler: https://github.com/rust-lang/rust/blob/2e2642e641a941f0a1400c7827fd89aa86fef8f4/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs#L466

I believe this issue can be fixed by adding a case for ty::Pat, along with an implementation for type_di_node. If/when this feature is ready for public use (i.e. can be constructed safely and does static proof-based analysis on its inputs), we should also have infrastructure like this.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs around line 466 and reproduce the ICE using the minimized Rust example in the issue. Trace type_di_node for the pattern type and investigate the suggested ty::Pat handling. Done means the example compiles without an internal compiler error while emitting debuginfo.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.