rust-lang/rust

ICE "compute_type_of_item: unexpected item type"

Closed this issue · 0 comments

Code

trait Bar {}

trait Foo {
    fn f() {}
}

impl Foo for dyn Bar {}

fn main() {
    Foo::f();
}

Error output

error: internal compiler error: compiler/rustc_hir_analysis/src/collect/type_of.rs:363:21: compute_type_of_item: unexpected item type: Trait(No, Normal, Generics { params: [], predicates: [], has_where_clause_predicates: false, where_clause_span: uiq.rs:1:10: 1:10 (#0), span: uiq.rs:1:10: 1:10 (#0) }, [], [])
 --> uiq.rs:1:1
  |
1 | trait Bar {}
  | ^^^^^^^^^^^^
Backtrace
thread 'rustc' panicked at 'Box<dyn Any>', /rustc/e75aab045fc476f176a58c408f6b06f0e275c6e1/compiler/rustc_errors/src/lib.rs:967:33
stack backtrace:
   0:        0x107842f12 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1b594e9bcc0c6898
   1:        0x1078a14ba - core::fmt::write::h7c6f83d024852aa9
   2:        0x107834fec - std::io::Write::write_fmt::h97d969d4aea1606d
   3:        0x107842cda - std::sys_common::backtrace::print::h562dadf6028256bf
   4:        0x1078460b6 - std::panicking::default_hook::{{closure}}::hee367e24075678e4
   5:        0x107845e07 - std::panicking::default_hook::hcce3553a0befadd1
   6:        0x1191b0f3d - rustc_driver[f93b8a3886cc8b65]::DEFAULT_HOOK::{closure#0}::{closure#0}
   7:        0x1078468b5 - std::panicking::rust_panic_with_hook::h4f6feaafc55c56a2
   8:        0x11bc01a77 - std[38dd6138ba148cb2]::panicking::begin_panic::<rustc_errors[ef89fc2f19a46f90]::ExplicitBug>::{closure#0}
   9:        0x11bbfb139 - std[38dd6138ba148cb2]::sys_common::backtrace::__rust_end_short_backtrace::<std[38dd6138ba148cb2]::panicking::begin_panic<rustc_errors[ef89fc2f19a46f90]::ExplicitBug>::{closure#0}, !>
  10:        0x11de4ef29 - std[38dd6138ba148cb2]::panicking::begin_panic::<rustc_errors[ef89fc2f19a46f90]::ExplicitBug>
  11:        0x11bcca9c9 - std[38dd6138ba148cb2]::panic::panic_any::<rustc_errors[ef89fc2f19a46f90]::ExplicitBug>
  12:        0x11bcc1308 - <rustc_errors[ef89fc2f19a46f90]::HandlerInner>::span_bug::<rustc_span[50ad8565b2f1bbfb]::span_encoding::Span, &alloc[dd1f1a43ef059f04]::string::String>
  13:        0x11bcc102e - <rustc_errors[ef89fc2f19a46f90]::Handler>::span_bug::<rustc_span[50ad8565b2f1bbfb]::span_encoding::Span, &alloc[dd1f1a43ef059f04]::string::String>
  14:        0x11bc89b71 - rustc_middle[85091bb6846d2e9a]::ty::context::tls::with_context_opt::<rustc_middle[85091bb6846d2e9a]::ty::context::tls::with_opt<rustc_middle[85091bb6846d2e9a]::util::bug::opt_span_bug_fmt<rustc_span[50ad8565b2f1bbfb]::span_encoding::Span>::{closure#0}, ()>::{closure#0}, ()>
  15:        0x11bc89a21 - rustc_middle[85091bb6846d2e9a]::util::bug::opt_span_bug_fmt::<rustc_span[50ad8565b2f1bbfb]::span_encoding::Span>
  16:        0x11de4efcf - rustc_middle[85091bb6846d2e9a]::util::bug::span_bug_fmt::<rustc_span[50ad8565b2f1bbfb]::span_encoding::Span>
  17:        0x11bc3a869 - rustc_hir_analysis[e85e3b9a54dc24a9]::collect::type_of::type_of
  18:        0x11c9c5c95 - rustc_query_system[38b064a260926677]::query::plumbing::try_execute_query::<rustc_query_impl[fcf86a589ba14889]::plumbing::QueryCtxt, rustc_query_system[38b064a260926677]::query::caches::DefaultCache<rustc_span[50ad8565b2f1bbfb]::def_id::DefId, rustc_middle[85091bb6846d2e9a]::ty::Ty>>
  19:        0x11caa9e24 - rustc_query_system[38b064a260926677]::query::plumbing::get_query::<rustc_query_impl[fcf86a589ba14889]::queries::type_of, rustc_query_impl[fcf86a589ba14889]::plumbing::QueryCtxt>
  20:        0x11d7252f2 - <rustc_infer[f3d18b0d0d8e0a5e]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[fbfc9000665c881]::traits::error_reporting::InferCtxtPrivExt>::maybe_report_ambiguity
  21:        0x11d714256 - <rustc_infer[f3d18b0d0d8e0a5e]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[fbfc9000665c881]::traits::error_reporting::TypeErrCtxtExt>::report_fulfillment_errors
  22:        0x11ba1e37f - <rustc_hir_typeck[bdb15a1f3923c127]::fn_ctxt::FnCtxt>::select_all_obligations_or_error
  23:        0x11baf8b93 - <rustc_hir_typeck[bdb15a1f3923c127]::inherited::InheritedBuilder>::enter::<rustc_hir_typeck[bdb15a1f3923c127]::typeck_with_fallback<rustc_hir_typeck[bdb15a1f3923c127]::typeck::{closure#0}>::{closure#0}::{closure#1}, &rustc_middle[85091bb6846d2e9a]::ty::context::TypeckResults>
  24:        0x11ba91ffa - rustc_hir_typeck[bdb15a1f3923c127]::typeck
  25:        0x11c9a4159 - rustc_query_system[38b064a260926677]::query::plumbing::try_execute_query::<rustc_query_impl[fcf86a589ba14889]::plumbing::QueryCtxt, rustc_query_system[38b064a260926677]::query::caches::DefaultCache<rustc_span[50ad8565b2f1bbfb]::def_id::LocalDefId, &rustc_middle[85091bb6846d2e9a]::ty::context::TypeckResults>>
  26:        0x11caa9b8c - rustc_query_system[38b064a260926677]::query::plumbing::get_query::<rustc_query_impl[fcf86a589ba14889]::queries::typeck, rustc_query_impl[fcf86a589ba14889]::plumbing::QueryCtxt>
  27:        0x11bb2176c - std[38dd6138ba148cb2]::panicking::try::<(), core[322641b34a183a]::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures[2eed7d44fa552923]::sync::par_for_each_in<&[rustc_span[50ad8565b2f1bbfb]::def_id::LocalDefId], <rustc_middle[85091bb6846d2e9a]::hir::map::Map>::par_body_owners<rustc_hir_typeck[bdb15a1f3923c127]::typeck_item_bodies::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}>>
  28:        0x11bb214a5 - rustc_data_structures[2eed7d44fa552923]::sync::par_for_each_in::<&[rustc_span[50ad8565b2f1bbfb]::def_id::LocalDefId], <rustc_middle[85091bb6846d2e9a]::hir::map::Map>::par_body_owners<rustc_hir_typeck[bdb15a1f3923c127]::typeck_item_bodies::{closure#0}>::{closure#0}>
  29:        0x11ba9177d - rustc_hir_typeck[bdb15a1f3923c127]::typeck_item_bodies
  30:        0x11ca3ddb9 - rustc_query_system[38b064a260926677]::query::plumbing::try_execute_query::<rustc_query_impl[fcf86a589ba14889]::plumbing::QueryCtxt, rustc_query_system[38b064a260926677]::query::caches::DefaultCache<(), ()>>
  31:        0x11ca9e339 - rustc_query_system[38b064a260926677]::query::plumbing::get_query::<rustc_query_impl[fcf86a589ba14889]::queries::typeck_item_bodies, rustc_query_impl[fcf86a589ba14889]::plumbing::QueryCtxt>
  32:        0x11bc0a3f4 - <rustc_session[304ed9bc7c986c94]::session::Session>::time::<(), rustc_hir_analysis[e85e3b9a54dc24a9]::check_crate::{closure#7}>
  33:        0x11bd295df - rustc_hir_analysis[e85e3b9a54dc24a9]::check_crate
  34:        0x1192743ba - rustc_interface[bab52cec3fba6e57]::passes::analysis
  35:        0x11ca2fb7c - rustc_query_system[38b064a260926677]::query::plumbing::try_execute_query::<rustc_query_impl[fcf86a589ba14889]::plumbing::QueryCtxt, rustc_query_system[38b064a260926677]::query::caches::DefaultCache<(), core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>>
  36:        0x11caa9f39 - rustc_query_system[38b064a260926677]::query::plumbing::get_query::<rustc_query_impl[fcf86a589ba14889]::queries::analysis, rustc_query_impl[fcf86a589ba14889]::plumbing::QueryCtxt>
  37:        0x119140416 - <rustc_interface[bab52cec3fba6e57]::passes::QueryContext>::enter::<rustc_driver[f93b8a3886cc8b65]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>
  38:        0x11918468d - rustc_span[50ad8565b2f1bbfb]::with_source_map::<core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>, rustc_interface[bab52cec3fba6e57]::interface::run_compiler<core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>, rustc_driver[f93b8a3886cc8b65]::run_compiler::{closure#1}>::{closure#0}::{closure#1}>
  39:        0x1191745bc - <scoped_tls[5d80669e9829205e]::ScopedKey<rustc_span[50ad8565b2f1bbfb]::SessionGlobals>>::set::<rustc_interface[bab52cec3fba6e57]::interface::run_compiler<core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>, rustc_driver[f93b8a3886cc8b65]::run_compiler::{closure#1}>::{closure#0}, core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>
  40:        0x11914337a - std[38dd6138ba148cb2]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[bab52cec3fba6e57]::util::run_in_thread_pool_with_globals<rustc_interface[bab52cec3fba6e57]::interface::run_compiler<core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>, rustc_driver[f93b8a3886cc8b65]::run_compiler::{closure#1}>::{closure#0}, core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>
  41:        0x119129b4b - <<std[38dd6138ba148cb2]::thread::Builder>::spawn_unchecked_<rustc_interface[bab52cec3fba6e57]::util::run_in_thread_pool_with_globals<rustc_interface[bab52cec3fba6e57]::interface::run_compiler<core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>, rustc_driver[f93b8a3886cc8b65]::run_compiler::{closure#1}>::{closure#0}, core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>::{closure#1} as core[322641b34a183a]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  42:        0x10784f967 - std::sys::unix::thread::Thread::new::thread_start::hae9a83a2ac729f3b
  43:     0x7ff80d84d4e1 - __pthread_start

note: 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: rustc 1.67.0-nightly (e75aab045 2022-11-09) running on x86_64-apple-darwin

query stack during panic:
#0 [type_of] computing type of `Bar`
#1 [typeck] type-checking `main`
#2 [typeck_item_bodies] type-checking all item bodies
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

Regression

Regression in nightly-2022-10-06, more specifically in rollup dd8c3a8.

Likely from #102670, which modified this error message.

Error message prior to the change
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
  --> uiq.rs:10:5
   |
4  |     fn f() {}
   |     --------- `Foo::f` defined here
...
10 |     Foo::f();
   |     ^^^^^^ cannot call associated function of trait
   |
help: use the fully-qualified path to the only available implementation
   |
10 |     <::Bar as Foo>::f();
   |     +++++++++    +

error: aborting due to previous error

Version

rustc 1.67.0-nightly (e75aab045 2022-11-09)
binary: rustc
commit-hash: e75aab045fc476f176a58c408f6b06f0e275c6e1
commit-date: 2022-11-09
host: x86_64-apple-darwin
release: 1.67.0-nightly
LLVM version: 15.0.4