Skip to content

Unreachable code in type_name.rs #144994

@TrueDoctor

Description

@TrueDoctor

Code

Compile with cargo build --lib playground

use std::marker::PhantomData;

pub trait HasLifetime<'a> {}

pub trait TypeName<Input> {
    fn type_name(&self) -> &'static str {
        std::any::type_name::<Input>()
    }
}

type Any = Box<dyn HasLifetime<'static>>;

pub struct A<I>(PhantomData<I>);

impl<I> TypeName<Any> for A<I> {}

fn register_node() {
    let any: A<()> = A(PhantomData);
    let _ = &any as &dyn TypeName<Any>;
}
pub static TEST: fn() = register_node;

Meta

rustc --version --verbose:

rustc 1.91.0-nightly (ec7c02612 2025-08-05)
binary: rustc
commit-hash: ec7c02612527d185c379900b613311bc1dcbf7dc
commit-date: 2025-08-05
host: x86_64-unknown-linux-gnu
release: 1.91.0-nightly
LLVM version: 20.1.8

Error output

thread 'rustc' panicked at compiler/rustc_const_eval/src/util/type_name.rs:21:9:
internal error: entered unreachable code
Backtrace

Graphite2/node-graph/gcore on  ice-debugging [✘?] ➜ RUST_BACKTRACE=1 cargo build --lib
warning: profile package spec `graphene-std` in profile `dev` did not match any packages
warning: profile package spec `graphite-editor` in profile `dev` did not match any packages
warning: profile package spec `graphite-proc-macros` in profile `dev` did not match any packages
warning: profile package spec `image` in profile `dev` did not match any packages
warning: profile package spec `interpreted-executor` in profile `dev` did not match any packages
warning: profile package spec `rustc-hash` in profile `dev` did not match any packages
   Compiling graphene-core v0.1.0 (/home/dennis/Projects/rust/Graphite2/node-graph/gcore)

thread 'rustc' panicked at compiler/rustc_const_eval/src/util/type_name.rs:21:9:
internal error: entered unreachable code
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: <rustc_const_eval::util::type_name::AbsolutePathPrinter as rustc_middle::ty::print::Printer>::print_region
   4: <rustc_middle::ty::generic_args::GenericArg as rustc_middle::ty::print::Print<rustc_const_eval::util::type_name::AbsolutePathPrinter>>::print.cold
   5: <rustc_const_eval::util::type_name::AbsolutePathPrinter as rustc_middle::ty::print::pretty::PrettyPrinter>::pretty_print_dyn_existential
   6: <rustc_const_eval::util::type_name::AbsolutePathPrinter as rustc_middle::ty::print::pretty::PrettyPrinter>::pretty_print_type
   7: <rustc_const_eval::util::type_name::AbsolutePathPrinter as rustc_middle::ty::print::Printer>::default_print_def_path
   8: rustc_const_eval::interpret::intrinsics::alloc_type_name
   9: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::eval_intrinsic
  10: <rustc_const_eval::const_eval::machine::CompileTimeMachine as rustc_const_eval::interpret::machine::Machine>::call_intrinsic
  11: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::init_fn_call
  12: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider
      [... omitted 3 frames ...]
  13: rustc_const_eval::const_eval::eval_queries::eval_to_const_value_raw_provider
      [... omitted 3 frames ...]
  14: <rustc_middle::ty::context::TyCtxt>::const_eval_resolve
  15: rustc_monomorphize::collector::items_of_instance
      [... omitted 1 frame ...]
  16: rustc_monomorphize::collector::collect_items_rec
  17: rustc_monomorphize::collector::collect_items_rec
  18: rustc_monomorphize::collector::collect_items_rec
  19: rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure#0}
  20: rustc_monomorphize::partitioning::collect_and_partition_mono_items
      [... omitted 6 frames ...]
  21: <rustc_metadata::rmeta::encoder::EncodeContext>::encode_crate_root
  22: <rustc_metadata::rmeta::encoder::encode_metadata::{closure#3} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, &std::path::Path)>>::call_once
  23: <rustc_middle::dep_graph::DepsType as rustc_query_system::dep_graph::Deps>::with_deps::<<rustc_query_system::dep_graph::graph::DepGraphData<rustc_middle::dep_graph::DepsType>>::with_task<rustc_middle::ty::context::TyCtxt, &std::path::Path, ()>::{closure#1}::{closure#0}, ()>
  24: rustc_metadata::rmeta::encoder::encode_metadata
  25: rustc_metadata::fs::encode_and_write_metadata
  26: <rustc_interface::queries::Linker>::codegen_and_build_linker
  27: 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}
  28: 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: please make sure that you have updated to the latest nightly

note: please attach the file at `/home/dennis/Projects/rust/Graphite2/rustc-ice-2025-08-06T11_28_32-2619648.txt` to your bug report

note: compiler flags: --crate-type lib -C opt-level=1 -C embed-bitcode=no -C debuginfo=2 -C debug-assertions=on -C linker=clang -C incremental=[REDACTED] -C link-arg=-fuse-ld=/nix/store/4a99sfc0vvzaqs0ywkgxr480a3dmy8n3-mold-2.40.2/bin/mold

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

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `core::any::type_name::{constant#0}`
#1 [eval_to_const_value_raw] simplifying constant for the type system `core::any::type_name::{constant#0}`
#2 [items_of_instance] collecting items used by `core::any::type_name::<alloc::boxed::Box<dyn HasLifetime<'_>>>`
#3 [collect_and_partition_mono_items] collect_and_partition_mono_items
#4 [exported_generic_symbols] collecting exported generic symbols for crate `0`
end of query stack
there was a panic while trying to force a dep node
try_mark_green dep node stack:
#0 exported_generic_symbols(graphene_core[e93f])
end of try_mark_green dep node stack
error: could not compile `graphene-core` (lib)

Caused by:
  process didn't exit successfully: `rustc --crate-name graphene_core --edition=2024 node-graph/gcore/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=90 --crate-type lib --emit=dep-info,metadata,link -C opt-level=1 -C embed-bitcode=no -C debuginfo=2 -C debug-assertions=on --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values("dealloc_nodes", "nightly", "type_id_logging"))' -C metadata=b6027afb23eb31f3 -C extra-filename=-813a045ef1cf077a --out-dir /home/dennis/Projects/rust/Graphite2/target/debug/deps -C linker=clang -C incremental=/home/dennis/Projects/rust/Graphite2/target/debug/incremental -L dependency=/home/dennis/Projects/rust/Graphite2/target/debug/deps -C link-arg=-fuse-ld=/nix/store/4a99sfc0vvzaqs0ywkgxr480a3dmy8n3-mold-2.40.2/bin/mold` (exit status: 101)

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-has-bisectionStatus: A bisection has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions