Closed
Description
The following code works in 1.56.0 but crashes 1.57.0 as well as the most recent nightly — rustc 1.59.0-nightly (0b42deacc 2021-12-09)
.
struct Struct<T>(T);
impl<T> std::ops::Deref for Struct<T> {
type Target = dyn Fn(T);
fn deref(&self) -> &Self::Target {
unimplemented!()
}
}
fn main() {
let f = Struct(Default::default());
f(0);
f(0);
}
$ cargo check
thread 'rustc' panicked at 'forcing query with already existing `DepNode`
- query-key: Binder(std::ops::FnOnce<({integer},)>, [])
- dep-node: own_existential_vtable_entries(5494fdf0afa3bf46-73ce537069178b52)', /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/compiler/rustc_query_system/src/dep_graph/graph.rs:236:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: internal compiler error: unexpected panic
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.59.0-nightly (0b42deacc 2021-12-09) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [own_existential_vtable_entries] finding all existential vtable entries for trait core::ops::function::FnOnce
#1 [evaluate_obligation] evaluating trait selection obligation `(dyn core::ops::function::Fn(^2_0) + 'static): core::ops::function::Fn<(^1_1,)>`
end of query stack
Backtrace
thread 'rustc' panicked at 'forcing query with already existing `DepNode`
- query-key: Binder(std::ops::FnOnce<({integer},)>, [])
- dep-node: own_existential_vtable_entries(5494fdf0afa3bf46-73ce537069178b52)', /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/compiler/rustc_query_system/src/dep_graph/graph.rs:236:9
stack backtrace:
0: rust_begin_unwind
at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/panicking.rs:498:5
1: core::panicking::panic_fmt
at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/core/src/panicking.rs:107:14
2: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::ExistentialTraitRef>, &[rustc_span::def_id::DefId]>
3: rustc_data_structures::stack::ensure_sufficient_stack::<(&[rustc_span::def_id::DefId], rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::ExistentialTraitRef>, &[rustc_span::def_id::DefId]>::{closure#3}>
4: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::own_existential_vtable_entries, rustc_query_impl::plumbing::QueryCtxt>
5: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::own_existential_vtable_entries
6: rustc_trait_selection::traits::util::count_own_vtable_entries
7: rustc_trait_selection::traits::vtable_trait_first_method_offset
8: <rustc_trait_selection::traits::select::SelectionContext>::confirm_candidate
9: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_stack
10: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_trait_predicate_recursively
11: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_root_obligation
12: <rustc_infer::infer::InferCtxtBuilder>::enter_with_canonical::<rustc_middle::ty::ParamEnvAnd<rustc_middle::ty::Predicate>, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>, rustc_traits::evaluate_obligation::evaluate_obligation::{closure#0}>
13: rustc_traits::evaluate_obligation::evaluate_obligation
14: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_middle::infer::canonical::Canonical<rustc_middle::ty::ParamEnvAnd<rustc_middle::ty::Predicate>>, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>>
15: rustc_data_structures::stack::ensure_sufficient_stack::<(core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, rustc_middle::infer::canonical::Canonical<rustc_middle::ty::ParamEnvAnd<rustc_middle::ty::Predicate>>, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>>::{closure#3}>
16: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::evaluate_obligation, rustc_query_impl::plumbing::QueryCtxt>
17: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::evaluate_obligation
18: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::predicate_may_hold
19: <rustc_typeck::check::fn_ctxt::FnCtxt>::lookup_method_in_trait
20: <rustc_typeck::check::fn_ctxt::FnCtxt>::try_overloaded_call_traits
21: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_call
22: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
23: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
24: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_stmt
25: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
26: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
27: rustc_typeck::check::check::check_fn
28: <rustc_infer::infer::InferCtxtBuilder>::enter::<&rustc_middle::ty::context::TypeckResults, <rustc_typeck::check::inherited::InheritedBuilder>::enter<rustc_typeck::check::typeck_with_fallback<rustc_typeck::check::typeck::{closure#0}>::{closure#1}, &rustc_middle::ty::context::TypeckResults>::{closure#0}>
29: rustc_typeck::check::typeck
30: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>
31: rustc_data_structures::stack::ensure_sufficient_stack::<(&rustc_middle::ty::context::TypeckResults, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>::{closure#3}>
32: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>>
33: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
34: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_typeck::check::typeck_item_bodies::{closure#0}>
35: rustc_typeck::check::typeck_item_bodies
36: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), ()>
37: rustc_data_structures::stack::ensure_sufficient_stack::<((), rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, (), ()>::{closure#3}>
38: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), ()>>
39: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::typeck_item_bodies, rustc_query_impl::plumbing::QueryCtxt>
40: <rustc_session::session::Session>::time::<(), rustc_typeck::check_crate::{closure#7}>
41: rustc_typeck::check_crate
42: rustc_interface::passes::analysis
43: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), core::result::Result<(), rustc_errors::ErrorReported>>
44: rustc_data_structures::stack::ensure_sufficient_stack::<(core::result::Result<(), rustc_errors::ErrorReported>, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, (), core::result::Result<(), rustc_errors::ErrorReported>>::{closure#3}>
45: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorReported>>>
46: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
47: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorReported>>
48: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
49: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
50: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: internal compiler error: unexpected panic
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.59.0-nightly (0b42deacc 2021-12-09) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [own_existential_vtable_entries] finding all existential vtable entries for trait core::ops::function::FnOnce
#1 [evaluate_obligation] evaluating trait selection obligation `(dyn core::ops::function::Fn(^2_0) + 'static): core::ops::function::Fn<(^1_1,)>`
#2 [typeck] type-checking `main`
#3 [typeck_item_bodies] type-checking all item bodies
#4 [analysis] running analysis passes on this crate
end of query stack