Skip to content

ICE: type_name intrinsic must be in const block or opted out #143587

@ackxolotl

Description

@ackxolotl

Code

    fn write_to_file<T>(&mut self, file: &str) -> Result<(), std::io::Error> {
        let fn_type = type_name::<T>();
        Ok(())
    }

Meta

rustc --version --verbose:

rustc 1.90.0-nightly (a84ab0ce6 2025-07-06)
binary: rustc
commit-hash: a84ab0ce6c4557a2f01a3a6c3fdb0f92098db78d
commit-date: 2025-07-06
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7

Error output

error: internal compiler error: /rustc-dev/a84ab0ce6c4557a2f01a3a6c3fdb0f92098db78d/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs:116:21: nullary intrinsic type_name must either be in a const block or explicitly opted out because it is inherently a runtime intrinsic
   --> src/codegen/mod.rs:187:23
    |
187 |         let fn_type = type_name::<T>();
    |                       ^^^^^^^^^^^^^^^^


thread 'rustc' panicked at /rustc-dev/a84ab0ce6c4557a2f01a3a6c3fdb0f92098db78d/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs:116:21:
Box<dyn Any>
stack backtrace:
   0:     0x7f6385f22963 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h3f3f54fb5c72b823
   1:     0x7f6386602c37 - core::fmt::write::hcca0132cd44f4053
   2:     0x7f6385f185a3 - std::io::Write::write_fmt::h78d6730f9875d14c
   3:     0x7f6385f227c2 - std::sys::backtrace::BacktraceLock::print::hf8d840a9b3ffa708
   4:     0x7f6385f2625a - std::panicking::default_hook::{{closure}}::h998a561f1734f2d1
   5:     0x7f6385f25ddf - std::panicking::default_hook::h0cdf50e26b2b744d
   6:     0x7f6384ff2bc3 - std[5392b2688ccf6c11]::panicking::update_hook::<alloc[6097bca32dba2b22]::boxed::Box<rustc_driver_impl[486328ec49f3cc14]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7f6385f26aab - std::panicking::rust_panic_with_hook::he4807f33a3524f43
   8:     0x7f638502cf11 - std[5392b2688ccf6c11]::panicking::begin_panic::<rustc_errors[a6d51e49eed9352d]::ExplicitBug>::{closure#0}
   9:     0x7f63850212d6 - std[5392b2688ccf6c11]::sys::backtrace::__rust_end_short_backtrace::<std[5392b2688ccf6c11]::panicking::begin_panic<rustc_errors[a6d51e49eed9352d]::ExplicitBug>::{closure#0}, !>
  10:     0x7f638501dc59 - std[5392b2688ccf6c11]::panicking::begin_panic::<rustc_errors[a6d51e49eed9352d]::ExplicitBug>
  11:     0x7f6385036991 - <rustc_errors[a6d51e49eed9352d]::diagnostic::BugAbort as rustc_errors[a6d51e49eed9352d]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7f638557907c - <rustc_errors[a6d51e49eed9352d]::DiagCtxtHandle>::span_bug::<rustc_span[5b31911843326824]::span_encoding::Span, alloc[6097bca32dba2b22]::string::String>
  13:     0x7f638560d2f7 - rustc_middle[e63663f80c63ef31]::util::bug::opt_span_bug_fmt::<rustc_span[5b31911843326824]::span_encoding::Span>::{closure#0}
  14:     0x7f63855ed8ba - rustc_middle[e63663f80c63ef31]::ty::context::tls::with_opt::<rustc_middle[e63663f80c63ef31]::util::bug::opt_span_bug_fmt<rustc_span[5b31911843326824]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:     0x7f63855ed72b - rustc_middle[e63663f80c63ef31]::ty::context::tls::with_context_opt::<rustc_middle[e63663f80c63ef31]::ty::context::tls::with_opt<rustc_middle[e63663f80c63ef31]::util::bug::opt_span_bug_fmt<rustc_span[5b31911843326824]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:     0x7f638311f907 - rustc_middle[e63663f80c63ef31]::util::bug::span_bug_fmt::<rustc_span[5b31911843326824]::span_encoding::Span>
  17:     0x7f638761dae1 - <rustc_codegen_ssa[1e451d6fccc2ba6f]::mir::FunctionCx<rustc_codegen_llvm[1b7fc3eed20d0400]::builder::GenericBuilder<rustc_codegen_llvm[1b7fc3eed20d0400]::context::FullCx>>>::codegen_intrinsic_call
  18:     0x7f6383064b2b - <rustc_codegen_ssa[1e451d6fccc2ba6f]::mir::FunctionCx<rustc_codegen_llvm[1b7fc3eed20d0400]::builder::GenericBuilder<rustc_codegen_llvm[1b7fc3eed20d0400]::context::FullCx>>>::codegen_terminator
  19:     0x7f638776c597 - rustc_codegen_ssa[1e451d6fccc2ba6f]::mir::codegen_mir::<rustc_codegen_llvm[1b7fc3eed20d0400]::builder::GenericBuilder<rustc_codegen_llvm[1b7fc3eed20d0400]::context::FullCx>>
  20:     0x7f638774cc0a - rustc_codegen_llvm[1b7fc3eed20d0400]::base::compile_codegen_unit::module_codegen
  21:     0x7f6387720c59 - <rustc_codegen_llvm[1b7fc3eed20d0400]::LlvmCodegenBackend as rustc_codegen_ssa[1e451d6fccc2ba6f]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  22:     0x7f638771e738 - rustc_codegen_ssa[1e451d6fccc2ba6f]::base::codegen_crate::<rustc_codegen_llvm[1b7fc3eed20d0400]::LlvmCodegenBackend>
  23:     0x7f63877e9a03 - <rustc_codegen_llvm[1b7fc3eed20d0400]::LlvmCodegenBackend as rustc_codegen_ssa[1e451d6fccc2ba6f]::traits::backend::CodegenBackend>::codegen_crate
  24:     0x7f63877e9091 - <rustc_interface[b1f97b06592f8920]::queries::Linker>::codegen_and_build_linker
  25:     0x7f63877e6b87 - rustc_interface[b1f97b06592f8920]::passes::create_and_enter_global_ctxt::<core[919d75d9604c1f70]::option::Option<rustc_interface[b1f97b06592f8920]::queries::Linker>, rustc_driver_impl[486328ec49f3cc14]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  26:     0x7f63878f29c3 - rustc_interface[b1f97b06592f8920]::interface::run_compiler::<(), rustc_driver_impl[486328ec49f3cc14]::run_compiler::{closure#0}>::{closure#1}
  27:     0x7f6387807e78 - std[5392b2688ccf6c11]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[b1f97b06592f8920]::util::run_in_thread_with_globals<rustc_interface[b1f97b06592f8920]::util::run_in_thread_pool_with_globals<rustc_interface[b1f97b06592f8920]::interface::run_compiler<(), rustc_driver_impl[486328ec49f3cc14]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  28:     0x7f6387807b56 - <<std[5392b2688ccf6c11]::thread::Builder>::spawn_unchecked_<rustc_interface[b1f97b06592f8920]::util::run_in_thread_with_globals<rustc_interface[b1f97b06592f8920]::util::run_in_thread_pool_with_globals<rustc_interface[b1f97b06592f8920]::interface::run_compiler<(), rustc_driver_impl[486328ec49f3cc14]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[919d75d9604c1f70]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  29:     0x7f638780617d - std::sys::pal::unix::thread::Thread::new::thread_start::h746b9bcf86250858
  30:     0x7f63812a57eb - <unknown>
  31:     0x7f638132918c - <unknown>
  32:                0x0 - <unknown>

note: using internal features is not supported and expected to cause internal compiler errors when used incorrectly

note: please attach the file at `rustc-ice-2025-07-07T13_50_46-57709.txt` to your bug report

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
end of query stack
Backtrace

   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: <rustc_errors::DiagCtxtHandle>::span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
   3: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   5: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   6: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
   7: <rustc_codegen_ssa::mir::FunctionCx<rustc_codegen_llvm::builder::GenericBuilder<rustc_codegen_llvm::context::FullCx>>>::codegen_intrinsic_call
   8: <rustc_codegen_ssa::mir::FunctionCx<rustc_codegen_llvm::builder::GenericBuilder<rustc_codegen_llvm::context::FullCx>>>::codegen_terminator
   9: rustc_codegen_ssa::mir::codegen_mir::<rustc_codegen_llvm::builder::GenericBuilder<rustc_codegen_llvm::context::FullCx>>
  10: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  11: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  12: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
  13: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  14: <rustc_interface::queries::Linker>::codegen_and_build_linker
  15: 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}
  16: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}

rustc-ice-2025-07-07T13_50_46-57709.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-internal-featuresThis issue requires the use of internal features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions