Skip to content

generic_const_items: Generic function pointer leads to ICEs during codegen #136156

Closed
@fmease

Description

@fmease

Reproducer:

#![feature(generic_const_items)]

const _IDENTITY<T>: fn(T) -> T = |x| x;

fn main() {}

Start of compiler output (stopping before backtrace):

warning: the feature `generic_const_items` is incomplete and may not be safe to use and/or cause compiler crashes
 --> oi.rs:1:12
  |
1 | #![feature(generic_const_items)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #113521 <https://github.com/rust-lang/rust/issues/113521> for more information
  = note: `#[warn(incomplete_features)]` on by default

error: internal compiler error: compiler/rustc_codegen_llvm/src/context.rs:1236:21: `fn_abi_of_instance(<{[email protected]:3:34: 3:37} as FnOnce<(T,)>>::call_once - shim, [])` failed: Layout(Unknown(T/#0))
   --> /home/fmease/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
    |
250 |     extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Rest of compiler output (includes backtrace)
warning: the feature `generic_const_items` is incomplete and may not be safe to use and/or cause compiler crashes
 --> oi.rs:1:12
  |
1 | #![feature(generic_const_items)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #113521 <https://github.com/rust-lang/rust/issues/113521> for more information
  = note: `#[warn(incomplete_features)]` on by default

error: internal compiler error: compiler/rustc_codegen_llvm/src/context.rs:1236:21: `fn_abi_of_instance(<{[email protected]:3:34: 3:37} as FnOnce<(T,)>>::call_once - shim, [])` failed: Layout(Unknown(T/#0))
   --> /home/fmease/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
    |
250 |     extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


thread 'rustc' panicked at compiler/rustc_codegen_llvm/src/context.rs:1236:21:
Box<dyn Any>
stack backtrace:
   0:     0x74ca1ac8ea90 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h2f23fd9f9d9d249c
   1:     0x74ca1b414f26 - core::fmt::write::hda581013c22cc38e
   2:     0x74ca1c378bd1 - std::io::Write::write_fmt::h7b67a2c48701ad74
   3:     0x74ca1ac8e8f2 - std::sys::backtrace::BacktraceLock::print::hf557d5f06e408e4b
   4:     0x74ca1ac90d72 - std::panicking::default_hook::{{closure}}::h003adb2133b1767b
   5:     0x74ca1ac90bfa - std::panicking::default_hook::h16009a902eb48a3c
   6:     0x74ca19e42759 - std[b112ec976dab40f4]::panicking::update_hook::<alloc[fdb5804898039ca3]::boxed::Box<rustc_driver_impl[8694186ee707eb2f]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x74ca1ac918f3 - std::panicking::rust_panic_with_hook::h1d06543d16cce998
   8:     0x74ca19e7d421 - std[b112ec976dab40f4]::panicking::begin_panic::<rustc_errors[98d48f3eae9e9f2e]::ExplicitBug>::{closure#0}
   9:     0x74ca19e72326 - std[b112ec976dab40f4]::sys::backtrace::__rust_end_short_backtrace::<std[b112ec976dab40f4]::panicking::begin_panic<rustc_errors[98d48f3eae9e9f2e]::ExplicitBug>::{closure#0}, !>
  10:     0x74ca19e720df - std[b112ec976dab40f4]::panicking::begin_panic::<rustc_errors[98d48f3eae9e9f2e]::ExplicitBug>
  11:     0x74ca19e87351 - <rustc_errors[98d48f3eae9e9f2e]::diagnostic::BugAbort as rustc_errors[98d48f3eae9e9f2e]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x74ca1a3e646c - <rustc_errors[98d48f3eae9e9f2e]::DiagCtxtHandle>::span_bug::<rustc_span[863c7cf5cfba53d9]::span_encoding::Span, alloc[fdb5804898039ca3]::string::String>
  13:     0x74ca1a46c4b7 - rustc_middle[a35b023f906b1e15]::util::bug::opt_span_bug_fmt::<rustc_span[863c7cf5cfba53d9]::span_encoding::Span>::{closure#0}
  14:     0x74ca1a451bfa - rustc_middle[a35b023f906b1e15]::ty::context::tls::with_opt::<rustc_middle[a35b023f906b1e15]::util::bug::opt_span_bug_fmt<rustc_span[863c7cf5cfba53d9]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:     0x74ca1a451a8b - rustc_middle[a35b023f906b1e15]::ty::context::tls::with_context_opt::<rustc_middle[a35b023f906b1e15]::ty::context::tls::with_opt<rustc_middle[a35b023f906b1e15]::util::bug::opt_span_bug_fmt<rustc_span[863c7cf5cfba53d9]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:     0x74ca18ed1a57 - rustc_middle[a35b023f906b1e15]::util::bug::span_bug_fmt::<rustc_span[863c7cf5cfba53d9]::span_encoding::Span>
  17:     0x74ca19cc5786 - <rustc_codegen_llvm[5b2e353c6d9ab786]::context::CodegenCx as rustc_middle[a35b023f906b1e15]::ty::layout::FnAbiOfHelpers>::handle_fn_abi_err
  18:     0x74ca19c9c6c8 - <rustc_codegen_llvm[5b2e353c6d9ab786]::context::CodegenCx as rustc_middle[a35b023f906b1e15]::ty::layout::FnAbiOf>::fn_abi_of_instance::{closure#0}
  19:     0x74ca1c31a5ce - <rustc_codegen_llvm[5b2e353c6d9ab786]::context::CodegenCx as rustc_codegen_ssa[763a256790c9aaeb]::traits::declare::PreDefineCodegenMethods>::predefine_fn
  20:     0x74ca1c317b2e - rustc_codegen_llvm[5b2e353c6d9ab786]::base::compile_codegen_unit::module_codegen
  21:     0x74ca1c402008 - <rustc_codegen_llvm[5b2e353c6d9ab786]::LlvmCodegenBackend as rustc_codegen_ssa[763a256790c9aaeb]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  22:     0x74ca1c3fe371 - <rustc_codegen_llvm[5b2e353c6d9ab786]::LlvmCodegenBackend as rustc_codegen_ssa[763a256790c9aaeb]::traits::backend::CodegenBackend>::codegen_crate
  23:     0x74ca1c405074 - <rustc_interface[7b6200b50ffd4527]::queries::Linker>::codegen_and_build_linker
  24:     0x74ca1c388a5d - rustc_interface[7b6200b50ffd4527]::passes::create_and_enter_global_ctxt::<core[1c802f461cf195ce]::option::Option<rustc_interface[7b6200b50ffd4527]::queries::Linker>, rustc_driver_impl[8694186ee707eb2f]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  25:     0x74ca1c3c3dd3 - rustc_interface[7b6200b50ffd4527]::interface::run_compiler::<(), rustc_driver_impl[8694186ee707eb2f]::run_compiler::{closure#0}>::{closure#1}
  26:     0x74ca1c2857f5 - std[b112ec976dab40f4]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[7b6200b50ffd4527]::util::run_in_thread_with_globals<rustc_interface[7b6200b50ffd4527]::util::run_in_thread_pool_with_globals<rustc_interface[7b6200b50ffd4527]::interface::run_compiler<(), rustc_driver_impl[8694186ee707eb2f]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  27:     0x74ca1c2854d9 - <<std[b112ec976dab40f4]::thread::Builder>::spawn_unchecked_<rustc_interface[7b6200b50ffd4527]::util::run_in_thread_with_globals<rustc_interface[7b6200b50ffd4527]::util::run_in_thread_pool_with_globals<rustc_interface[7b6200b50ffd4527]::interface::run_compiler<(), rustc_driver_impl[8694186ee707eb2f]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[1c802f461cf195ce]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  28:     0x74ca1c284c6f - std::sys::pal::unix::thread::Thread::new::thread_start::hf2e53aa54a2bf93d
  29:     0x74ca166a339d - <unknown>
  30:     0x74ca1672849c - <unknown>
  31:                0x0 - <unknown>

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: please make sure that you have updated to the latest nightly

note: rustc 1.86.0-nightly (1e9b0177d 2025-01-24) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
error: aborting due to 1 previous error; 1 warning emitted

error: process exited unsuccessfully: exit status: 101

Interestingly(?), this ICE doesn't occur if we don't coerce the closure to a function pointer:

#![feature(generic_const_items, type_alias_impl_trait)]

type Fn<T> = impl FnOnce(T) -> T;
const _IDENTITY<T>: Fn<T> = |x| x;

fn main() { /* _IDENTITY/*::<i32>*/(23); */ }

Metadata

Metadata

Assignees

Labels

A-monomorphizationArea: MonomorphizationC-bugCategory: This is a bug.F-generic_const_items`#![feature(generic_const_items)]`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-incomplete-featuresThis issue requires the use of incomplete features.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions