Closed
Description
"When the compiler of the safest programming language panics, doom shall come upon us"
Jokes aside, this is the snippet (aka "the destroyer of worlds"):
the panic happens when calling "set_closure", even tho there's no body inside that function.
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
pub struct Trader<'a> {
closure: Box<dyn Fn(&mut Trader) + 'a>,
}
impl<'a> Trader<'a> {
pub fn new() -> Self {
Trader {
closure: Box::new(|_| {}),
}
}
pub fn set_closure(&mut self, function: impl Fn(&mut Trader) + 'a) {
//foo
}
}
fn main() {
let closure = |trader : Trader| {
println!("Woooosh!");
};
let mut trader = Trader::new();
trader.set_closure(closure);
}
Cargo output:
`warning: field `amazingness` is never read
--> src/trader.rs:42:5
|
33 | pub struct Trader<'a> {
| ------ field in this struct
...
42 | amazingness: f32,
| ^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
Compiling trader v0.1.0 (/sources/trader)
warning: `trader` (lib) generated 1 warning
warning: unused import: `gtk::glib::closure`
--> src/lib.rs:12:9
|
12 | use gtk::glib::closure;
| ^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error: internal compiler error: compiler/rustc_infer/src/infer/region_constraints/mod.rs:568:17: cannot relate bound region: ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:118 ~ trader[966e]::tests::trader_example#1::'_), '_) }) <= ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed(DefId(0:105 ~ trader[966e]::trader::{impl#1}::set_closure::'_#2), '_) })
thread 'rustc' panicked at 'Box<dyn Any>', /rustc/52372f9c71d8ade4cb815524f179119656f0aa2e/compiler/rustc_errors/src/lib.rs:987:33
stack backtrace:
0: 0x7fe55356659a - std::backtrace_rs::backtrace::libunwind::trace::h6ee169f87c9eb811
at /rustc/52372f9c71d8ade4cb815524f179119656f0aa2e/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
1: 0x7fe55356659a - std::backtrace_rs::backtrace::trace_unsynchronized::hae1aa8caf0f73946
at /rustc/52372f9c71d8ade4cb815524f179119656f0aa2e/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x7fe55356659a - std::sys_common::backtrace::_print_fmt::hd0ae816e159c88c0
at /rustc/52372f9c71d8ade4cb815524f179119656f0aa2e/library/std/src/sys_common/backtrace.rs:65:5
3: 0x7fe55356659a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h73a43b159f05d7bf
at /rustc/52372f9c71d8ade4cb815524f179119656f0aa2e/library/std/src/sys_common/backtrace.rs:44:22
4: 0x7fe5535c839e - core::fmt::write::h098923995eefaba9
at /rustc/52372f9c71d8ade4cb815524f179119656f0aa2e/library/core/src/fmt/mod.rs:1213:17
5: 0x7fe553556ce5 - std::io::Write::write_fmt::h5f2525aec78434df
at /rustc/52372f9c71d8ade4cb815524f179119656f0aa2e/library/std/src/io/mod.rs:1682:15
6: 0x7fe553566365 - std::sys_common::backtrace::_print::h1dd4ca615e620472
at /rustc/52372f9c71d8ade4cb815524f179119656f0aa2e/library/std/src/sys_common/backtrace.rs:47:5
7: 0x7fe553566365 - std::sys_common::backtrace::print::hdaad52d464d17c88
at /rustc/52372f9c71d8ade4cb815524f179119656f0aa2e/library/std/src/sys_common/backtrace.rs:34:9
8: 0x7fe55356912f - std::panicking::default_hook::{{closure}}::h1c9cf4fd4a868b33
at /rustc/52372f9c71d8ade4cb815524f179119656f0aa2e/library/std/src/panicking.rs:267:22
9: 0x7fe553568e6b - std::panicking::default_hook::h3725ab7a4be0fc2f
at /rustc/52372f9c71d8ade4cb815524f179119656f0aa2e/library/std/src/panicking.rs:286:9
10: 0x7fe5568b3d84 - <rustc_driver[7258c8eabce1a5f1]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[2378a91e024a45a8]::ops::function::FnOnce<(&core[2378a91e024a45a8]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
11: 0x7fe55356996a - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h3f090c481fefe13f
at /rustc/52372f9c71d8ade4cb815524f179119656f0aa2e/library/alloc/src/boxed.rs:2002:9
12: 0x7fe55356996a - std::panicking::rust_panic_with_hook::hb7593c6583c1a088
at /rustc/52372f9c71d8ade4cb815524f179119656f0aa2e/library/std/src/panicking.rs:692:13
13: 0x7fe556b6f9f1 - std[794a501e8e4ddd]::panicking::begin_panic::<rustc_errors[ee9c5c934e200930]::ExplicitBug>::{closure#0}
14: 0x7fe556b68346 - std[794a501e8e4ddd]::sys_common::backtrace::__rust_end_short_backtrace::<std[794a501e8e4ddd]::panicking::begin_panic<rustc_errors[ee9c5c934e200930]::ExplicitBug>::{closure#0}, !>
15: 0x7fe556bf83d6 - std[794a501e8e4ddd]::panicking::begin_panic::<rustc_errors[ee9c5c934e200930]::ExplicitBug>
16: 0x7fe556bf83c6 - std[794a501e8e4ddd]::panic::panic_any::<rustc_errors[ee9c5c934e200930]::ExplicitBug>
17: 0x7fe556bf7172 - <rustc_errors[ee9c5c934e200930]::HandlerInner>::span_bug::<rustc_span[16a0acf2172c41aa]::span_encoding::Span, &alloc[d928f4df06acc700]::string::String>
18: 0x7fe556bf7017 - <rustc_errors[ee9c5c934e200930]::Handler>::span_bug::<rustc_span[16a0acf2172c41aa]::span_encoding::Span, &alloc[d928f4df06acc700]::string::String>
19: 0x7fe556bac66b - rustc_middle[95c9930f7ab52d77]::util::bug::opt_span_bug_fmt::<rustc_span[16a0acf2172c41aa]::span_encoding::Span>::{closure#0}
20: 0x7fe556bac6ba - rustc_middle[95c9930f7ab52d77]::ty::context::tls::with_opt::<rustc_middle[95c9930f7ab52d77]::util::bug::opt_span_bug_fmt<rustc_span[16a0acf2172c41aa]::span_encoding::Span>::{closure#0}, !>::{closure#0}
21: 0x7fe556bab77a - rustc_middle[95c9930f7ab52d77]::ty::context::tls::with_context_opt::<rustc_middle[95c9930f7ab52d77]::ty::context::tls::with_opt<rustc_middle[95c9930f7ab52d77]::util::bug::opt_span_bug_fmt<rustc_span[16a0acf2172c41aa]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
22: 0x7fe556bab6a6 - rustc_middle[95c9930f7ab52d77]::util::bug::opt_span_bug_fmt::<rustc_span[16a0acf2172c41aa]::span_encoding::Span>
23: 0x7fe556bab664 - rustc_middle[95c9930f7ab52d77]::util::bug::span_bug_fmt::<rustc_span[16a0acf2172c41aa]::span_encoding::Span>
24: 0x7fe554846524 - <rustc_middle[95c9930f7ab52d77]::ty::sty::Region as rustc_middle[95c9930f7ab52d77]::ty::relate::Relate>::relate::<rustc_infer[23accda3df25759c]::infer::equate::Equate>
25: 0x7fe5548417df - rustc_middle[95c9930f7ab52d77]::ty::relate::super_relate_tys::<rustc_infer[23accda3df25759c]::infer::equate::Equate>
26: 0x7fe55483e7de - <rustc_infer[23accda3df25759c]::infer::equate::Equate as rustc_middle[95c9930f7ab52d77]::ty::relate::TypeRelation>::tys
27: 0x7fe55514da63 - <rustc_infer[23accda3df25759c]::infer::InferCtxt>::commit_if_ok::<rustc_infer[23accda3df25759c]::infer::InferOk<()>, rustc_middle[95c9930f7ab52d77]::ty::error::TypeError, <rustc_infer[23accda3df25759c]::infer::at::Trace>::eq<rustc_middle[95c9930f7ab52d77]::ty::Ty>::{closure#0}>
28: 0x7fe55514d956 - <rustc_infer[23accda3df25759c]::infer::at::At>::eq::<rustc_middle[95c9930f7ab52d77]::ty::Ty>
29: 0x7fe557499b7e - <rustc_infer[23accda3df25759c]::infer::InferCtxt>::can_eq::<rustc_middle[95c9930f7ab52d77]::ty::Ty>
30: 0x7fe55747cab2 - rustc_trait_selection[91b8336cc642d8f1]::traits::error_reporting::suggestions::hint_missing_borrow
31: 0x7fe55751b8c4 - <rustc_infer[23accda3df25759c]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[91b8336cc642d8f1]::traits::error_reporting::suggestions::TypeErrCtxtExt>::report_closure_arg_mismatch
32: 0x7fe55752b718 - <rustc_infer[23accda3df25759c]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[91b8336cc642d8f1]::traits::error_reporting::TypeErrCtxtExt>::report_selection_error
33: 0x7fe5575350f7 - <rustc_infer[23accda3df25759c]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[91b8336cc642d8f1]::traits::error_reporting::InferCtxtPrivExt>::report_fulfillment_error
34: 0x7fe55752875f - <rustc_infer[23accda3df25759c]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[91b8336cc642d8f1]::traits::error_reporting::TypeErrCtxtExt>::report_fulfillment_errors
35: 0x7fe554ac33be - <rustc_hir_typeck[1674ffa0bfbd4f06]::fn_ctxt::FnCtxt>::check_argument_types
36: 0x7fe554a507ed - <rustc_hir_typeck[1674ffa0bfbd4f06]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
37: 0x7fe554a802c3 - <rustc_hir_typeck[1674ffa0bfbd4f06]::fn_ctxt::FnCtxt>::check_block_with_expected
38: 0x7fe554a4eaa5 - <rustc_hir_typeck[1674ffa0bfbd4f06]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
39: 0x7fe5549d6b41 - <rustc_hir_typeck[1674ffa0bfbd4f06]::fn_ctxt::FnCtxt>::check_return_expr
40: 0x7fe5549cd7ec - rustc_hir_typeck[1674ffa0bfbd4f06]::check::check_fn
41: 0x7fe5549b6c21 - <rustc_hir_typeck[1674ffa0bfbd4f06]::inherited::InheritedBuilder>::enter::<rustc_hir_typeck[1674ffa0bfbd4f06]::typeck_with_fallback<rustc_hir_typeck[1674ffa0bfbd4f06]::typeck::{closure#0}>::{closure#0}::{closure#1}, &rustc_middle[95c9930f7ab52d77]::ty::typeck_results::TypeckResults>
42: 0x7fe5549aa74b - rustc_hir_typeck[1674ffa0bfbd4f06]::typeck
43: 0x7fe5549b4077 - <rustc_query_system[bfbaafaf1990babf]::dep_graph::graph::DepGraph<rustc_middle[95c9930f7ab52d77]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[95c9930f7ab52d77]::ty::context::TyCtxt, rustc_span[16a0acf2172c41aa]::def_id::LocalDefId, &rustc_middle[95c9930f7ab52d77]::ty::typeck_results::TypeckResults>
44: 0x7fe5549a91ab - rustc_query_system[bfbaafaf1990babf]::query::plumbing::try_execute_query::<rustc_query_impl[667f5fceb3f08368]::queries::typeck, rustc_query_impl[667f5fceb3f08368]::plumbing::QueryCtxt>
45: 0x7fe55601036d - rustc_data_structures[1facfdae654cf19d]::sync::par_for_each_in::<&[rustc_span[16a0acf2172c41aa]::def_id::LocalDefId], <rustc_middle[95c9930f7ab52d77]::hir::map::Map>::par_body_owners<rustc_hir_typeck[1674ffa0bfbd4f06]::typeck_item_bodies::{closure#0}>::{closure#0}>
46: 0x7fe556010103 - rustc_hir_typeck[1674ffa0bfbd4f06]::typeck_item_bodies
47: 0x7fe556028857 - <rustc_query_system[bfbaafaf1990babf]::dep_graph::graph::DepGraph<rustc_middle[95c9930f7ab52d77]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[95c9930f7ab52d77]::ty::context::TyCtxt, (), ()>
48: 0x7fe555e36316 - rustc_query_system[bfbaafaf1990babf]::query::plumbing::try_execute_query::<rustc_query_impl[667f5fceb3f08368]::queries::typeck_item_bodies, rustc_query_impl[667f5fceb3f08368]::plumbing::QueryCtxt>
49: 0x7fe55627250b - <rustc_query_impl[667f5fceb3f08368]::Queries as rustc_middle[95c9930f7ab52d77]::ty::query::QueryEngine>::typeck_item_bodies
50: 0x7fe554d5da52 - <rustc_session[7082c254c65c125c]::session::Session>::time::<(), rustc_hir_analysis[cbd8fad8fc412dfa]::check_crate::{closure#7}>
51: 0x7fe554d5cec2 - rustc_hir_analysis[cbd8fad8fc412dfa]::check_crate
52: 0x7fe554d5cb1b - rustc_interface[b1381683ac399f9e]::passes::analysis
53: 0x7fe555fe0c26 - <rustc_query_system[bfbaafaf1990babf]::dep_graph::graph::DepGraph<rustc_middle[95c9930f7ab52d77]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[95c9930f7ab52d77]::ty::context::TyCtxt, (), core[2378a91e024a45a8]::result::Result<(), rustc_errors[ee9c5c934e200930]::ErrorGuaranteed>>
54: 0x7fe555fdfde1 - rustc_query_system[bfbaafaf1990babf]::query::plumbing::try_execute_query::<rustc_query_impl[667f5fceb3f08368]::queries::analysis, rustc_query_impl[667f5fceb3f08368]::plumbing::QueryCtxt>
55: 0x7fe55626eeca - <rustc_query_impl[667f5fceb3f08368]::Queries as rustc_middle[95c9930f7ab52d77]::ty::query::QueryEngine>::analysis
56: 0x7fe555a99a30 - <rustc_interface[b1381683ac399f9e]::passes::QueryContext>::enter::<rustc_driver[7258c8eabce1a5f1]::run_compiler::{closure#1}::{closure#2}::{closure#2}, core[2378a91e024a45a8]::result::Result<(), rustc_errors[ee9c5c934e200930]::ErrorGuaranteed>>
57: 0x7fe555a974a4 - rustc_span[16a0acf2172c41aa]::with_source_map::<core[2378a91e024a45a8]::result::Result<(), rustc_errors[ee9c5c934e200930]::ErrorGuaranteed>, rustc_interface[b1381683ac399f9e]::interface::run_compiler<core[2378a91e024a45a8]::result::Result<(), rustc_errors[ee9c5c934e200930]::ErrorGuaranteed>, rustc_driver[7258c8eabce1a5f1]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
58: 0x7fe555a8fec4 - <scoped_tls[a6ac3e8a9e7681d4]::ScopedKey<rustc_span[16a0acf2172c41aa]::SessionGlobals>>::set::<rustc_interface[b1381683ac399f9e]::interface::run_compiler<core[2378a91e024a45a8]::result::Result<(), rustc_errors[ee9c5c934e200930]::ErrorGuaranteed>, rustc_driver[7258c8eabce1a5f1]::run_compiler::{closure#1}>::{closure#0}, core[2378a91e024a45a8]::result::Result<(), rustc_errors[ee9c5c934e200930]::ErrorGuaranteed>>
59: 0x7fe555a8f5c2 - std[794a501e8e4ddd]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[b1381683ac399f9e]::util::run_in_thread_pool_with_globals<rustc_interface[b1381683ac399f9e]::interface::run_compiler<core[2378a91e024a45a8]::result::Result<(), rustc_errors[ee9c5c934e200930]::ErrorGuaranteed>, rustc_driver[7258c8eabce1a5f1]::run_compiler::{closure#1}>::{closure#0}, core[2378a91e024a45a8]::result::Result<(), rustc_errors[ee9c5c934e200930]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[2378a91e024a45a8]::result::Result<(), rustc_errors[ee9c5c934e200930]::ErrorGuaranteed>>
60: 0x7fe555a8f36a - <<std[794a501e8e4ddd]::thread::Builder>::spawn_unchecked_<rustc_interface[b1381683ac399f9e]::util::run_in_thread_pool_with_globals<rustc_interface[b1381683ac399f9e]::interface::run_compiler<core[2378a91e024a45a8]::result::Result<(), rustc_errors[ee9c5c934e200930]::ErrorGuaranteed>, rustc_driver[7258c8eabce1a5f1]::run_compiler::{closure#1}>::{closure#0}, core[2378a91e024a45a8]::result::Result<(), rustc_errors[ee9c5c934e200930]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[2378a91e024a45a8]::result::Result<(), rustc_errors[ee9c5c934e200930]::ErrorGuaranteed>>::{closure#1} as core[2378a91e024a45a8]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
61: 0x7fe553573823 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h782c58d991e3a9fa
at /rustc/52372f9c71d8ade4cb815524f179119656f0aa2e/library/alloc/src/boxed.rs:1988:9
62: 0x7fe553573823 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc76ad755b506b7de
at /rustc/52372f9c71d8ade4cb815524f179119656f0aa2e/library/alloc/src/boxed.rs:1988:9
63: 0x7fe553573823 - std::sys::unix::thread::Thread::new::thread_start::hf6469066c81feebd
at /rustc/52372f9c71d8ade4cb815524f179119656f0aa2e/library/std/src/sys/unix/thread.rs:108:17
64: 0x7fe5532d18fd - <unknown>
65: 0x7fe553353a60 - <unknown>
66: 0x0 - <unknown>
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.68.0-nightly (52372f9c7 2023-01-21) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [typeck] type-checking `tests::trader_example`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack
warning: `trader` (lib test) generated 1 warning (run `cargo fix --lib -p trader --tests` to apply 1 suggestion)
error: could not compile `trader`; 1 warning emitted`