Skip to content

ICE: compute_type_of_item: unexpected item type: Trait #135418

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
matthiaskrgr opened this issue Jan 12, 2025 · 2 comments · Fixed by #135493
Closed

ICE: compute_type_of_item: unexpected item type: Trait #135418

matthiaskrgr opened this issue Jan 12, 2025 · 2 comments · Fixed by #135493
Assignees
Labels
C-bug Category: This is a bug. 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. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

snippet:

//@compile-flags: -Clink-dead-code=true
trait SelfStruct<'x, 's, T>
where
    [T; (|| {}, 1).1]: Copy,
{
}

pub fn main() {}

Version information

rustc 1.86.0-nightly (627513a76 2025-01-12)
binary: rustc
commit-hash: 627513a764a696b59bb2679cc1731a197a088a1d
commit-date: 2025-01-12
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.6

Possibly related line of code:

| ItemKind::Macro(..)
| ItemKind::Mod(..)
| ItemKind::ForeignMod { .. }
| ItemKind::GlobalAsm(..)
| ItemKind::ExternCrate(..)
| ItemKind::Use(..) => {
span_bug!(item.span, "compute_type_of_item: unexpected item type: {:?}", item.kind);
}
},
Node::OpaqueTy(..) => tcx.type_of_opaque(def_id).map_or_else(
|CyclePlaceholder(guar)| Ty::new_error(tcx, guar),
|ty| ty.instantiate_identity(),

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Clink-dead-code=true

Program output

warning: trait `SelfStruct` is never used
 --> /tmp/icemaker_global_tempdir.DEnKVgcGaF35/rustc_testrunner_tmpdir_reporting.wm567l8VVNDr/mvce.rs:1:7
  |
1 | trait SelfStruct<'x, 's, T>
  |       ^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

error: internal compiler error: compiler/rustc_hir_analysis/src/collect/type_of.rs:314:17: compute_type_of_item: unexpected item type: Trait(No, Safe, Generics { params: [GenericParam { hir_id: HirId(DefId(0:3 ~ mvce[0784]::SelfStruct).15), def_id: DefId(0:4 ~ mvce[0784]::SelfStruct::'x), name: Plain('x#0), span: /tmp/icemaker_global_tempdir.DEnKVgcGaF35/rustc_testrunner_tmpdir_reporting.wm567l8VVNDr/mvce.rs:1:18: 1:20 (#0), pure_wrt_drop: false, kind: Lifetime { kind: Explicit }, colon_span: None, source: Generics }, GenericParam { hir_id: HirId(DefId(0:3 ~ mvce[0784]::SelfStruct).16), def_id: DefId(0:5 ~ mvce[0784]::SelfStruct::'s), name: Plain('s#0), span: /tmp/icemaker_global_tempdir.DEnKVgcGaF35/rustc_testrunner_tmpdir_reporting.wm567l8VVNDr/mvce.rs:1:22: 1:24 (#0), pure_wrt_drop: false, kind: Lifetime { kind: Explicit }, colon_span: None, source: Generics }, GenericParam { hir_id: HirId(DefId(0:3 ~ mvce[0784]::SelfStruct).17), def_id: DefId(0:6 ~ mvce[0784]::SelfStruct::T), name: Plain(T#0), span: /tmp/icemaker_global_tempdir.DEnKVgcGaF35/rustc_testrunner_tmpdir_reporting.wm567l8VVNDr/mvce.rs:1:26: 1:27 (#0), pure_wrt_drop: false, kind: Type { default: None, synthetic: false }, colon_span: None, source: Generics }], predicates: [WherePredicate { hir_id: HirId(DefId(0:3 ~ mvce[0784]::SelfStruct).1), span: /tmp/icemaker_global_tempdir.DEnKVgcGaF35/rustc_testrunner_tmpdir_reporting.wm567l8VVNDr/mvce.rs:3:5: 3:28 (#0), kind: BoundPredicate(WhereBoundPredicate { origin: WhereClause, bound_generic_params: [], bounded_ty: Ty { hir_id: HirId(DefId(0:3 ~ mvce[0784]::SelfStruct).12), kind: Array(Ty { hir_id: HirId(DefId(0:3 ~ mvce[0784]::SelfStruct).2), kind: Path(Resolved(None, Path { span: /tmp/icemaker_global_tempdir.DEnKVgcGaF35/rustc_testrunner_tmpdir_reporting.wm567l8VVNDr/mvce.rs:3:6: 3:7 (#0), res: Def(TyParam, DefId(0:6 ~ mvce[0784]::SelfStruct::T)), segments: [PathSegment { ident: T#0, hir_id: HirId(DefId(0:3 ~ mvce[0784]::SelfStruct).3), res: Def(TyParam, DefId(0:6 ~ mvce[0784]::SelfStruct::T)), args: None, infer_args: false }] })), span: /tmp/icemaker_global_tempdir.DEnKVgcGaF35/rustc_testrunner_tmpdir_reporting.wm567l8VVNDr/mvce.rs:3:6: 3:7 (#0) }, ConstArg { hir_id: HirId(DefId(0:3 ~ mvce[0784]::SelfStruct).11), kind: Anon(AnonConst { hir_id: HirId(DefId(0:3 ~ mvce[0784]::SelfStruct).4), def_id: DefId(0:7 ~ mvce[0784]::SelfStruct::{constant#0}), body: BodyId { hir_id: HirId(DefId(0:3 ~ mvce[0784]::SelfStruct).5) }, span: /tmp/icemaker_global_tempdir.DEnKVgcGaF35/rustc_testrunner_tmpdir_reporting.wm567l8VVNDr/mvce.rs:3:9: 3:21 (#0) }) }), span: /tmp/icemaker_global_tempdir.DEnKVgcGaF35/rustc_testrunner_tmpdir_reporting.wm567l8VVNDr/mvce.rs:3:5: 3:22 (#0) }, bounds: [Trait(PolyTraitRef { bound_generic_params: [], modifiers: TraitBoundModifiers { constness: Never, polarity: Positive }, trait_ref: TraitRef { path: Path { span: /tmp/icemaker_global_tempdir.DEnKVgcGaF35/rustc_testrunner_tmpdir_reporting.wm567l8VVNDr/mvce.rs:3:24: 3:28 (#0), res: Def(Trait, DefId(2:3495 ~ core[0a3a]::marker::Copy)), segments: [PathSegment { ident: Copy#0, hir_id: HirId(DefId(0:3 ~ mvce[0784]::SelfStruct).13), res: Def(Trait, DefId(2:3495 ~ core[0a3a]::marker::Copy)), args: None, infer_args: false }] }, hir_ref_id: HirId(DefId(0:3 ~ mvce[0784]::SelfStruct).14) }, span: /tmp/icemaker_global_tempdir.DEnKVgcGaF35/rustc_testrunner_tmpdir_reporting.wm567l8VVNDr/mvce.rs:3:24: 3:28 (#0) })] }) }], has_where_clause_predicates: true, where_clause_span: /tmp/icemaker_global_tempdir.DEnKVgcGaF35/rustc_testrunner_tmpdir_reporting.wm567l8VVNDr/mvce.rs:2:1: 3:29 (#0), span: /tmp/icemaker_global_tempdir.DEnKVgcGaF35/rustc_testrunner_tmpdir_reporting.wm567l8VVNDr/mvce.rs:1:17: 1:28 (#0) }, [], [])
 --> /tmp/icemaker_global_tempdir.DEnKVgcGaF35/rustc_testrunner_tmpdir_reporting.wm567l8VVNDr/mvce.rs:1:1
  |
1 | / trait SelfStruct<'x, 's, T>
2 | | where
3 | |     [T; (|| {}, 1).1]: Copy,
4 | | {
5 | | }
  | |_^


thread 'rustc' panicked at compiler/rustc_hir_analysis/src/collect/type_of.rs:314:17:
Box<dyn Any>
stack backtrace:
   0:     0x74cf6b6f6cba - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hb6d52abf03d3c762
   1:     0x74cf6be12d66 - core::fmt::write::ha1f096bf27753534
   2:     0x74cf6cda72d1 - std::io::Write::write_fmt::h7b63b7192c8b84e8
   3:     0x74cf6b6f6b12 - std::sys::backtrace::BacktraceLock::print::he1317dcd3671a83c
   4:     0x74cf6b6f90b7 - std::panicking::default_hook::{{closure}}::h5104547d98fde4b9
   5:     0x74cf6b6f8ea0 - std::panicking::default_hook::h00c5a74868336544
   6:     0x74cf6a85ef68 - std[66958f67114116ef]::panicking::update_hook::<alloc[73a44396601e81ad]::boxed::Box<rustc_driver_impl[c9f89440d3758e47]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x74cf6b6f9903 - std::panicking::rust_panic_with_hook::hffe642292ec7a3ed
   8:     0x74cf6a897db1 - std[66958f67114116ef]::panicking::begin_panic::<rustc_errors[2c74e16010a12992]::ExplicitBug>::{closure#0}
   9:     0x74cf6a88ccb6 - std[66958f67114116ef]::sys::backtrace::__rust_end_short_backtrace::<std[66958f67114116ef]::panicking::begin_panic<rustc_errors[2c74e16010a12992]::ExplicitBug>::{closure#0}, !>
  10:     0x74cf6a8897c9 - std[66958f67114116ef]::panicking::begin_panic::<rustc_errors[2c74e16010a12992]::ExplicitBug>
  11:     0x74cf6a8a1ce1 - <rustc_errors[2c74e16010a12992]::diagnostic::BugAbort as rustc_errors[2c74e16010a12992]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x74cf6adf886c - <rustc_errors[2c74e16010a12992]::DiagCtxtHandle>::span_bug::<rustc_span[d3aaf222917fc9d0]::span_encoding::Span, alloc[73a44396601e81ad]::string::String>
  13:     0x74cf6ae7d5d7 - rustc_middle[3aac817982ce6052]::util::bug::opt_span_bug_fmt::<rustc_span[d3aaf222917fc9d0]::span_encoding::Span>::{closure#0}
  14:     0x74cf6ae62f1a - rustc_middle[3aac817982ce6052]::ty::context::tls::with_opt::<rustc_middle[3aac817982ce6052]::util::bug::opt_span_bug_fmt<rustc_span[d3aaf222917fc9d0]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:     0x74cf6ae62dab - rustc_middle[3aac817982ce6052]::ty::context::tls::with_context_opt::<rustc_middle[3aac817982ce6052]::ty::context::tls::with_opt<rustc_middle[3aac817982ce6052]::util::bug::opt_span_bug_fmt<rustc_span[d3aaf222917fc9d0]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:     0x74cf69846017 - rustc_middle[3aac817982ce6052]::util::bug::span_bug_fmt::<rustc_span[d3aaf222917fc9d0]::span_encoding::Span>
  17:     0x74cf6bed600a - rustc_hir_analysis[6ef5ea017ebe40aa]::collect::type_of::type_of
  18:     0x74cf6becf7f8 - rustc_query_impl[dddd50ae2b86f84d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[dddd50ae2b86f84d]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3aac817982ce6052]::query::erase::Erased<[u8; 8usize]>>
  19:     0x74cf6bece59f - rustc_query_system[6587ccb57284e1c7]::query::plumbing::try_execute_query::<rustc_query_impl[dddd50ae2b86f84d]::DynamicConfig<rustc_query_system[6587ccb57284e1c7]::query::caches::DefIdCache<rustc_middle[3aac817982ce6052]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[dddd50ae2b86f84d]::plumbing::QueryCtxt, false>
  20:     0x74cf6bece12b - rustc_query_impl[dddd50ae2b86f84d]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  21:     0x74cf6c945630 - rustc_symbol_mangling[cd10110488156193]::legacy::mangle
  22:     0x74cf6c941187 - rustc_symbol_mangling[cd10110488156193]::symbol_name_provider
  23:     0x74cf6c94092a - rustc_query_impl[dddd50ae2b86f84d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[dddd50ae2b86f84d]::query_impl::symbol_name::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3aac817982ce6052]::query::erase::Erased<[u8; 16usize]>>
  24:     0x74cf6c93f8b7 - rustc_query_system[6587ccb57284e1c7]::query::plumbing::try_execute_query::<rustc_query_impl[dddd50ae2b86f84d]::DynamicConfig<rustc_query_system[6587ccb57284e1c7]::query::caches::DefaultCache<rustc_middle[3aac817982ce6052]::ty::instance::Instance, rustc_middle[3aac817982ce6052]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[dddd50ae2b86f84d]::plumbing::QueryCtxt, false>
  25:     0x74cf6c93f522 - rustc_query_impl[dddd50ae2b86f84d]::query_impl::symbol_name::get_query_non_incr::__rust_end_short_backtrace
  26:     0x74cf6c93b302 - <rustc_middle[3aac817982ce6052]::mir::mono::MonoItem>::symbol_name
  27:     0x74cf6c93adfd - rustc_monomorphize[1c1f6e9040afc7a4]::partitioning::assert_symbols_are_distinct::<core[a3a276ad4f05d2a]::slice::iter::Iter<rustc_middle[3aac817982ce6052]::mir::mono::MonoItem>>
  28:     0x74cf6c869579 - rustc_monomorphize[1c1f6e9040afc7a4]::partitioning::collect_and_partition_mono_items
  29:     0x74cf6cdcc9d6 - rustc_query_impl[dddd50ae2b86f84d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[dddd50ae2b86f84d]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3aac817982ce6052]::query::erase::Erased<[u8; 24usize]>>
  30:     0x74cf6cdcc9b7 - <rustc_query_impl[dddd50ae2b86f84d]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[a3a276ad4f05d2a]::ops::function::FnOnce<(rustc_middle[3aac817982ce6052]::ty::context::TyCtxt, ())>>::call_once
  31:     0x74cf6cdcc53c - rustc_query_system[6587ccb57284e1c7]::query::plumbing::try_execute_query::<rustc_query_impl[dddd50ae2b86f84d]::DynamicConfig<rustc_query_system[6587ccb57284e1c7]::query::caches::SingleCache<rustc_middle[3aac817982ce6052]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[dddd50ae2b86f84d]::plumbing::QueryCtxt, false>
  32:     0x74cf6cdcc234 - rustc_query_impl[dddd50ae2b86f84d]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  33:     0x74cf6ce8daa0 - <rustc_codegen_llvm[d754e186fb816fa0]::LlvmCodegenBackend as rustc_codegen_ssa[89dde8d707ccbd3c]::traits::backend::CodegenBackend>::codegen_crate
  34:     0x74cf6ce42ee4 - <rustc_interface[9c0c46cd854ea960]::queries::Linker>::codegen_and_build_linker
  35:     0x74cf6ce38852 - rustc_interface[9c0c46cd854ea960]::passes::create_and_enter_global_ctxt::<core[a3a276ad4f05d2a]::option::Option<rustc_interface[9c0c46cd854ea960]::queries::Linker>, rustc_driver_impl[c9f89440d3758e47]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  36:     0x74cf6ce1af96 - rustc_interface[9c0c46cd854ea960]::interface::run_compiler::<(), rustc_driver_impl[c9f89440d3758e47]::run_compiler::{closure#0}>::{closure#1}
  37:     0x74cf6cc7c511 - std[66958f67114116ef]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[9c0c46cd854ea960]::util::run_in_thread_with_globals<rustc_interface[9c0c46cd854ea960]::util::run_in_thread_pool_with_globals<rustc_interface[9c0c46cd854ea960]::interface::run_compiler<(), rustc_driver_impl[c9f89440d3758e47]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  38:     0x74cf6cc7c9c4 - <<std[66958f67114116ef]::thread::Builder>::spawn_unchecked_<rustc_interface[9c0c46cd854ea960]::util::run_in_thread_with_globals<rustc_interface[9c0c46cd854ea960]::util::run_in_thread_pool_with_globals<rustc_interface[9c0c46cd854ea960]::interface::run_compiler<(), rustc_driver_impl[c9f89440d3758e47]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[a3a276ad4f05d2a]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  39:     0x74cf6cc7df6f - std::sys::pal::unix::thread::Thread::new::thread_start::h11552343380d0134
  40:     0x74cf6705f39d - <unknown>
  41:     0x74cf670e449c - <unknown>
  42:                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 (627513a76 2025-01-12) running on x86_64-unknown-linux-gnu

note: compiler flags: -C link-dead-code=true -Z dump-mir-dir=dir

query stack during panic:
#0 [type_of] computing type of `SelfStruct`
#1 [symbol_name] computing the symbol for `SelfStruct::{constant#0}::{closure#0}`
#2 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to 1 previous error; 1 warning emitted


@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. 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. labels Jan 12, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 12, 2025
@matthiaskrgr
Copy link
Member Author

this compiled before
regression in #135314 cc @compiler-errors

@compiler-errors compiler-errors self-assigned this Jan 13, 2025
@saethlin saethlin added T-types Relevant to the types team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 13, 2025
@matthiaskrgr
Copy link
Member Author

smaller

trait A<T>
where
    [T; (|| {}, 1).1]: Sized,
{
}

@bors bors closed this as completed in f9c2c12 Jan 14, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 14, 2025
Rollup merge of rust-lang#135493 - compiler-errors:legacy-mangle-closure, r=lqd

Fix legacy symbol mangling of closures

When this code was written, there was no `type_of` implementation for closures. That has long since been changed.

In the UI test:

```
trait A where
    [(); (|| {}, 1).1]: Sized,
{
}
```

We tried to walk up the def path tree for the closure, from closure -> anon const -> trait. When we reached the trait, we tried to call `type_of` on it which obviously doesn't do the right thing and ICEs.

Fixes rust-lang#135418
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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants