Skip to content
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

ICE DefId(2:2587 ~ core[22a2]::default) does not have a "generics_of" #113610

Closed
matthiaskrgr opened this issue Jul 12, 2023 · 4 comments · Fixed by #113651
Closed

ICE DefId(2:2587 ~ core[22a2]::default) does not have a "generics_of" #113610

matthiaskrgr opened this issue Jul 12, 2023 · 4 comments · Fixed by #113651
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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.

Comments

@matthiaskrgr
Copy link
Member

Code

fn test5() {
    let t = (String::new(), Default::default());
}

Meta

rustc --version --verbose:

rustc 1.73.0-nightly (e571544f4 2023-07-11)
binary: rustc
commit-hash: e571544f4448d35af55e5ea3f35b92a2e784944a
commit-date: 2023-07-11
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5

Error output

<output>
Backtrace

error[E0601]: `main` function not found in crate `treereduce`
 --> treereduce.out:3:2
  |
3 | }
  |  ^ consider adding a `main` function to `treereduce.out`

thread 'rustc' panicked at 'DefId(2:2587 ~ core[22a2]::default) does not have a "generics_of"', compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs:205:1
stack backtrace:
   0:     0x7f2664763641 - std::backtrace_rs::backtrace::libunwind::trace::hca29094809d9477a
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f2664763641 - std::backtrace_rs::backtrace::trace_unsynchronized::h9c93fbc346e32491
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f2664763641 - std::sys_common::backtrace::_print_fmt::h0fe57bfefd15b201
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f2664763641 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3a49877b0c514b39
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f26647c974f - core::fmt::rt::Argument::fmt::h7f9f051156e40db0
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/core/src/fmt/rt.rs:138:9
   5:     0x7f26647c974f - core::fmt::write::ha9b9d271548a73c5
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/core/src/fmt/mod.rs:1094:21
   6:     0x7f2664755ed7 - std::io::Write::write_fmt::hc362527f94e7bd48
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/std/src/io/mod.rs:1714:15
   7:     0x7f2664763455 - std::sys_common::backtrace::_print::h7d0ea49c208d574d
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f2664763455 - std::sys_common::backtrace::print::he03f8dd1ce343041
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f2664766233 - std::panicking::default_hook::{{closure}}::h07a8a0e03842f254
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/std/src/panicking.rs:269:22
  10:     0x7f2664765fc4 - std::panicking::default_hook::hbe55e2858525ddb4
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/std/src/panicking.rs:288:9
  11:     0x7f26679e0d8b - <rustc_driver_impl[b031cc87a12e3f83]::install_ice_hook::{closure#0} as core[22a2682dd47ad7ab]::ops::function::FnOnce<(&core[22a2682dd47ad7ab]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  12:     0x7f2664766a5e - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hdae7ac5f67d0fe74
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/alloc/src/boxed.rs:2007:9
  13:     0x7f2664766a5e - std::panicking::rust_panic_with_hook::haff772a1c5ad3ee6
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/std/src/panicking.rs:709:13
  14:     0x7f26647667e7 - std::panicking::begin_panic_handler::{{closure}}::h8a44092b35d95f6d
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/std/src/panicking.rs:597:13
  15:     0x7f2664763aa6 - std::sys_common::backtrace::__rust_end_short_backtrace::h696f84c223c173c4
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/std/src/sys_common/backtrace.rs:151:18
  16:     0x7f2664766532 - rust_begin_unwind
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/std/src/panicking.rs:593:5
  17:     0x7f26647c59a3 - core::panicking::panic_fmt::hb3d524c9bc244750
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/core/src/panicking.rs:67:14
  18:     0x7f2667ed8a02 - rustc_metadata[9d79889a4dcec7f8]::rmeta::decoder::cstore_impl::provide_extern::generics_of::{closure#2}
  19:     0x7f26664059dd - rustc_query_impl[43d7f214d4bda649]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[43d7f214d4bda649]::query_impl::generics_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[30f3b0c932b04da5]::query::erase::Erased<[u8; 8usize]>>
  20:     0x7f26664054a0 - <rustc_query_impl[43d7f214d4bda649]::query_impl::generics_of::dynamic_query::{closure#2} as core[22a2682dd47ad7ab]::ops::function::FnOnce<(rustc_middle[30f3b0c932b04da5]::ty::context::TyCtxt, rustc_span[1515c77db744f4cd]::def_id::DefId)>>::call_once
  21:     0x7f2665a6a2f5 - rustc_query_system[b940c10253c7f285]::query::plumbing::try_execute_query::<rustc_query_impl[43d7f214d4bda649]::DynamicConfig<rustc_query_system[b940c10253c7f285]::query::caches::DefaultCache<rustc_span[1515c77db744f4cd]::def_id::DefId, rustc_middle[30f3b0c932b04da5]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[43d7f214d4bda649]::plumbing::QueryCtxt, false>
  22:     0x7f2667334dc3 - rustc_query_impl[43d7f214d4bda649]::query_impl::generics_of::get_query_non_incr::__rust_end_short_backtrace
  23:     0x7f2667d5c270 - rustc_middle[30f3b0c932b04da5]::query::plumbing::query_get_at::<rustc_query_system[b940c10253c7f285]::query::caches::DefaultCache<rustc_span[1515c77db744f4cd]::def_id::DefId, rustc_middle[30f3b0c932b04da5]::query::erase::Erased<[u8; 8usize]>>>
  24:     0x7f2667d5f505 - rustc_infer[a89e4bd38e23cb11]::infer::error_reporting::need_type_info::fmt_printer::{closure#0}
  25:     0x7f2665b3457a - <rustc_middle[30f3b0c932b04da5]::ty::print::pretty::FmtPrinter as rustc_middle[30f3b0c932b04da5]::ty::print::pretty::PrettyPrinter>::pretty_print_type
  26:     0x7f2665b354a6 - <rustc_middle[30f3b0c932b04da5]::ty::print::pretty::FmtPrinter as rustc_middle[30f3b0c932b04da5]::ty::print::pretty::PrettyPrinter>::comma_sep::<rustc_middle[30f3b0c932b04da5]::ty::Ty, core[22a2682dd47ad7ab]::iter::adapters::copied::Copied<core[22a2682dd47ad7ab]::slice::iter::Iter<rustc_middle[30f3b0c932b04da5]::ty::Ty>>>
  27:     0x7f2665b32975 - <rustc_middle[30f3b0c932b04da5]::ty::print::pretty::FmtPrinter as rustc_middle[30f3b0c932b04da5]::ty::print::pretty::PrettyPrinter>::pretty_print_type
  28:     0x7f2667d5f9e9 - rustc_infer[a89e4bd38e23cb11]::infer::error_reporting::need_type_info::ty_to_string
  29:     0x7f2667d5fd42 - <rustc_infer[a89e4bd38e23cb11]::infer::error_reporting::need_type_info::InferSourceKind>::ty_localized_msg
  30:     0x7f2667d181a6 - <rustc_infer[a89e4bd38e23cb11]::infer::error_reporting::TypeErrCtxt>::emit_inference_failure_err
  31:     0x7f26686298bb - <rustc_infer[a89e4bd38e23cb11]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[c6863b135aac8412]::traits::error_reporting::InferCtxtPrivExt>::maybe_report_ambiguity
  32:     0x7f266861c1b4 - <rustc_infer[a89e4bd38e23cb11]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[c6863b135aac8412]::traits::error_reporting::TypeErrCtxtExt>::report_fulfillment_errors
  33:     0x7f2666535116 - rustc_hir_typeck[6f9a7622c205e574]::typeck
  34:     0x7f2665a6d79e - rustc_query_impl[43d7f214d4bda649]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[43d7f214d4bda649]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[30f3b0c932b04da5]::query::erase::Erased<[u8; 8usize]>>
  35:     0x7f2665a6d76e - <rustc_query_impl[43d7f214d4bda649]::query_impl::typeck::dynamic_query::{closure#2} as core[22a2682dd47ad7ab]::ops::function::FnOnce<(rustc_middle[30f3b0c932b04da5]::ty::context::TyCtxt, rustc_span[1515c77db744f4cd]::def_id::LocalDefId)>>::call_once
  36:     0x7f2665b37fad - rustc_query_system[b940c10253c7f285]::query::plumbing::try_execute_query::<rustc_query_impl[43d7f214d4bda649]::DynamicConfig<rustc_query_system[b940c10253c7f285]::query::caches::VecCache<rustc_span[1515c77db744f4cd]::def_id::LocalDefId, rustc_middle[30f3b0c932b04da5]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[43d7f214d4bda649]::plumbing::QueryCtxt, false>
  37:     0x7f266730d9d1 - rustc_query_impl[43d7f214d4bda649]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  38:     0x7f2665baffed - rustc_query_impl[43d7f214d4bda649]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[43d7f214d4bda649]::query_impl::used_trait_imports::dynamic_query::{closure#2}::{closure#0}, rustc_middle[30f3b0c932b04da5]::query::erase::Erased<[u8; 8usize]>>
  39:     0x7f2665baff4e - <rustc_query_impl[43d7f214d4bda649]::query_impl::used_trait_imports::dynamic_query::{closure#2} as core[22a2682dd47ad7ab]::ops::function::FnOnce<(rustc_middle[30f3b0c932b04da5]::ty::context::TyCtxt, rustc_span[1515c77db744f4cd]::def_id::LocalDefId)>>::call_once
  40:     0x7f2665b37fad - rustc_query_system[b940c10253c7f285]::query::plumbing::try_execute_query::<rustc_query_impl[43d7f214d4bda649]::DynamicConfig<rustc_query_system[b940c10253c7f285]::query::caches::VecCache<rustc_span[1515c77db744f4cd]::def_id::LocalDefId, rustc_middle[30f3b0c932b04da5]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[43d7f214d4bda649]::plumbing::QueryCtxt, false>
  41:     0x7f2667340da1 - rustc_query_impl[43d7f214d4bda649]::query_impl::used_trait_imports::get_query_non_incr::__rust_end_short_backtrace
  42:     0x7f2666e7ef92 - rustc_hir_analysis[82b5e16c7bfda3fb]::check_unused::check_crate
  43:     0x7f2666e7c431 - rustc_hir_analysis[82b5e16c7bfda3fb]::check_crate
  44:     0x7f2666e758ba - rustc_interface[4d7121c82a192bc1]::passes::analysis
  45:     0x7f2666e717da - rustc_query_impl[43d7f214d4bda649]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[43d7f214d4bda649]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[30f3b0c932b04da5]::query::erase::Erased<[u8; 1usize]>>
  46:     0x7f2666e717c9 - <rustc_query_impl[43d7f214d4bda649]::query_impl::analysis::dynamic_query::{closure#2} as core[22a2682dd47ad7ab]::ops::function::FnOnce<(rustc_middle[30f3b0c932b04da5]::ty::context::TyCtxt, ())>>::call_once
  47:     0x7f26670259e8 - rustc_query_system[b940c10253c7f285]::query::plumbing::try_execute_query::<rustc_query_impl[43d7f214d4bda649]::DynamicConfig<rustc_query_system[b940c10253c7f285]::query::caches::SingleCache<rustc_middle[30f3b0c932b04da5]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[43d7f214d4bda649]::plumbing::QueryCtxt, false>
  48:     0x7f26670257b9 - rustc_query_impl[43d7f214d4bda649]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  49:     0x7f2666c15ec2 - <rustc_interface[4d7121c82a192bc1]::queries::QueryResult<&rustc_middle[30f3b0c932b04da5]::ty::context::GlobalCtxt>>::enter::<core[22a2682dd47ad7ab]::result::Result<(), rustc_span[1515c77db744f4cd]::ErrorGuaranteed>, rustc_driver_impl[b031cc87a12e3f83]::run_compiler::{closure#1}::{closure#2}::{closure#4}>
  50:     0x7f2666c14bd8 - <rustc_interface[4d7121c82a192bc1]::interface::Compiler>::enter::<rustc_driver_impl[b031cc87a12e3f83]::run_compiler::{closure#1}::{closure#2}, core[22a2682dd47ad7ab]::result::Result<core[22a2682dd47ad7ab]::option::Option<rustc_interface[4d7121c82a192bc1]::queries::Linker>, rustc_span[1515c77db744f4cd]::ErrorGuaranteed>>
  51:     0x7f2666c0e0c5 - rustc_span[1515c77db744f4cd]::set_source_map::<core[22a2682dd47ad7ab]::result::Result<(), rustc_span[1515c77db744f4cd]::ErrorGuaranteed>, rustc_interface[4d7121c82a192bc1]::interface::run_compiler<core[22a2682dd47ad7ab]::result::Result<(), rustc_span[1515c77db744f4cd]::ErrorGuaranteed>, rustc_driver_impl[b031cc87a12e3f83]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  52:     0x7f2666c0db36 - <scoped_tls[cc875c8f9ac7d91b]::ScopedKey<rustc_span[1515c77db744f4cd]::SessionGlobals>>::set::<rustc_interface[4d7121c82a192bc1]::interface::run_compiler<core[22a2682dd47ad7ab]::result::Result<(), rustc_span[1515c77db744f4cd]::ErrorGuaranteed>, rustc_driver_impl[b031cc87a12e3f83]::run_compiler::{closure#1}>::{closure#0}, core[22a2682dd47ad7ab]::result::Result<(), rustc_span[1515c77db744f4cd]::ErrorGuaranteed>>
  53:     0x7f2666c0d0fc - std[671b5e6e5c144e0c]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[4d7121c82a192bc1]::util::run_in_thread_pool_with_globals<rustc_interface[4d7121c82a192bc1]::interface::run_compiler<core[22a2682dd47ad7ab]::result::Result<(), rustc_span[1515c77db744f4cd]::ErrorGuaranteed>, rustc_driver_impl[b031cc87a12e3f83]::run_compiler::{closure#1}>::{closure#0}, core[22a2682dd47ad7ab]::result::Result<(), rustc_span[1515c77db744f4cd]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[22a2682dd47ad7ab]::result::Result<(), rustc_span[1515c77db744f4cd]::ErrorGuaranteed>>
  54:     0x7f2667204985 - <<std[671b5e6e5c144e0c]::thread::Builder>::spawn_unchecked_<rustc_interface[4d7121c82a192bc1]::util::run_in_thread_pool_with_globals<rustc_interface[4d7121c82a192bc1]::interface::run_compiler<core[22a2682dd47ad7ab]::result::Result<(), rustc_span[1515c77db744f4cd]::ErrorGuaranteed>, rustc_driver_impl[b031cc87a12e3f83]::run_compiler::{closure#1}>::{closure#0}, core[22a2682dd47ad7ab]::result::Result<(), rustc_span[1515c77db744f4cd]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[22a2682dd47ad7ab]::result::Result<(), rustc_span[1515c77db744f4cd]::ErrorGuaranteed>>::{closure#1} as core[22a2682dd47ad7ab]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  55:     0x7f26647710f5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h94c741346229c08a
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/alloc/src/boxed.rs:1993:9
  56:     0x7f26647710f5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1fff289ef1c1875a
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/alloc/src/boxed.rs:1993:9
  57:     0x7f26647710f5 - std::sys::unix::thread::Thread::new::thread_start::hc34b652bcf2ee8ff
                               at /rustc/e571544f4448d35af55e5ea3f35b92a2e784944a/library/std/src/sys/unix/thread.rs:108:17
  58:     0x7f266450344b - <unknown>
  59:     0x7f2664586e40 - <unknown>
  60:                0x0 - <unknown>

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: rustc 1.73.0-nightly (e571544f4 2023-07-11) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [generics_of] computing generics of `core::default`
#1 [typeck] type-checking `test5`
#2 [used_trait_imports] finding used_trait_imports `test5`
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

For more information about this error, try `rustc --explain E0601`.

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

#113310 cc @jieyouxu

@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 12, 2023
@jieyouxu
Copy link
Member

jieyouxu commented Jul 12, 2023

Thanks for the ping. It seems to be that here

if let TypeVariableOriginKind::TypeParameterDefinition(name, def_id) = var_origin.kind
&& !var_origin.span.from_expansion()
{
let generics = infcx.tcx.generics_of(infcx.tcx.parent(def_id));

it's not always the parent tcx.parent(def_id) which has generics_of, sometimes its on the def_id as-is. I'm not entirely sure when we need the tcx.parent (IIRC it doesn't work for my test case if I don't add tcx.parent).

@jieyouxu
Copy link
Member

jieyouxu commented Jul 12, 2023

Now if I stick to only using def_id and not its parent,

debug!(?def_id);
let generics = infcx.tcx.generics_of(def_id);
debug!("generics: {:?}", generics);
let idx = generics.param_def_id_to_index(infcx.tcx, def_id).unwrap();

the param_def_id_to_index line ICEs on my PR's test case because it can't find the param index for the def_id.

trait T {}

struct S {}

impl S {
    fn owo(&self, _: Option<&impl T>) {}
}

fn main() {
    (S {}).owo(None)
    //~^ ERROR type annotations needed
}
├─0ms DEBUG rustc_infer::infer::error_reporting::need_type_info def_id=DefId(0:10 ~ issue_113264_incorrect_impl_trait_in_path_suggestion[bb87]::{impl#0}::owo::{opaque#0})
├─0ms DEBUG rustc_infer::infer::error_reporting::need_type_info generics: Generics { parent: None, parent_count: 0, params: [], param_def_id_to_index: {}, has_self: false, has_late_bound_regions: None, host_effect_index: None }

cc @lcnr sorry for the ping, but do you know if impl T here is special somehow? The DefId debug path for my PR's test case seems to have another layer compared to this issue's ICE example, namely {opaque#0}. I think this is why getting param_def_id_to_index for my PR test case's parent worked but not for this ICE?

@lcnr
Copy link
Contributor

lcnr commented Jul 13, 2023

going to look into this, I think using parent is correct and the bug is somewhere else 😅

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jul 14, 2023
@bors bors closed this as completed in eca9c01 Jul 17, 2023
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. glacier ICE tracked in rust-lang/glacier. 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants