Repository: rust
Issue: "Cannot Relate Bound Region" causing panic at Box<dyn Any> in Compiler
Labels: I-ICE,T-compiler,C-bug

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->

I tried running `cargo build` on this commit: https://github.com/SamuelSchlesinger/valheim-damage/commit/1d3efd0bc33261e945e833d11514b101ad958c34 
As there is a `rust-toolchain` file in there, this is on the nightly.

I expected to see this happen: Code builds or I get a reasonable compiler error. I get a reasonable compiler error on the stable branch.

Instead, this happened: 

```
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(30:611 ~ plotters[d9f2]::chart::context::{impl#1}::draw_series::'b), 'b) }) <= '_#59r

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/015a824f2dffe32707fceb59c47effaf7b73486c/compiler/rustc_errors/src/lib.rs:1393:9
stack backtrace:
   0:     0x7f24f5c6d820 - std::backtrace_rs::backtrace::libunwind::trace::h7bdac8deb0a70b12
                               at /rustc/015a824f2dffe32707fceb59c47effaf7b73486c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   1:     0x7f24f5c6d820 - std::backtrace_rs::backtrace::trace_unsynchronized::h6759e48bcb134623
                               at /rustc/015a824f2dffe32707fceb59c47effaf7b73486c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f24f5c6d820 - std::sys_common::backtrace::_print_fmt::hee5bb84515b9b5c5
                               at /rustc/015a824f2dffe32707fceb59c47effaf7b73486c/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f24f5c6d820 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hbddd048486d5ff8d
                               at /rustc/015a824f2dffe32707fceb59c47effaf7b73486c/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f24f5cc86ae - core::fmt::write::h4587f7900e14b85a
                               at /rustc/015a824f2dffe32707fceb59c47effaf7b73486c/library/core/src/fmt/mod.rs:1202:17
   5:     0x7f24f5c5e5a5 - std::io::Write::write_fmt::h97b37adbc66ad057
                               at /rustc/015a824f2dffe32707fceb59c47effaf7b73486c/library/std/src/io/mod.rs:1672:15
   6:     0x7f24f5c704d3 - std::sys_common::backtrace::_print::hcf4df344fadcea08
                               at /rustc/015a824f2dffe32707fceb59c47effaf7b73486c/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f24f5c704d3 - std::sys_common::backtrace::print::hda6dada57be6ec72
                               at /rustc/015a824f2dffe32707fceb59c47effaf7b73486c/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f24f5c704d3 - std::panicking::default_hook::{{closure}}::ha1a5933c8f092e04
                               at /rustc/015a824f2dffe32707fceb59c47effaf7b73486c/library/std/src/panicking.rs:295:22
   9:     0x7f24f5c701bf - std::panicking::default_hook::h6c3e1f6c588c7c6e
                               at /rustc/015a824f2dffe32707fceb59c47effaf7b73486c/library/std/src/panicking.rs:314:9
  10:     0x7f24f84bbaf4 - rustc_driver[4d9024b7109a74ec]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f24f5c70d0d - std::panicking::rust_panic_with_hook::hf13ccf9af9efb117
                               at /rustc/015a824f2dffe32707fceb59c47effaf7b73486c/library/std/src/panicking.rs:702:17
  12:     0x7f24f93cbc91 - std[e55f2e3b0b26feec]::panicking::begin_panic::<rustc_errors[b9540f85d88fac40]::ExplicitBug>::{closure#0}
  13:     0x7f24f93c7326 - std[e55f2e3b0b26feec]::sys_common::backtrace::__rust_end_short_backtrace::<std[e55f2e3b0b26feec]::panicking::begin_panic<rustc_errors[b9540f85d88fac40]::ExplicitBug>::{closure#0}, !>
  14:     0x7f24f93ab186 - std[e55f2e3b0b26feec]::panicking::begin_panic::<rustc_errors[b9540f85d88fac40]::ExplicitBug>
  15:     0x7f24f936aa66 - std[e55f2e3b0b26feec]::panic::panic_any::<rustc_errors[b9540f85d88fac40]::ExplicitBug>
  16:     0x7f24f9369ec1 - <rustc_errors[b9540f85d88fac40]::HandlerInner>::span_bug::<rustc_span[ddffbb6e99b71f22]::span_encoding::Span, &alloc[f00d5a5fca4da78c]::string::String>
  17:     0x7f24f9369d80 - <rustc_errors[b9540f85d88fac40]::Handler>::span_bug::<rustc_span[ddffbb6e99b71f22]::span_encoding::Span, &alloc[f00d5a5fca4da78c]::string::String>
  18:     0x7f24f936afb8 - rustc_middle[d56cef6af7a8b1f3]::ty::context::tls::with_context_opt::<rustc_middle[d56cef6af7a8b1f3]::ty::context::tls::with_opt<rustc_middle[d56cef6af7a8b1f3]::util::bug::opt_span_bug_fmt<rustc_span[ddffbb6e99b71f22]::span_encoding::Span>::{closure#0}, ()>::{closure#0}, ()>
  19:     0x7f24f936ae56 - rustc_middle[d56cef6af7a8b1f3]::util::bug::opt_span_bug_fmt::<rustc_span[ddffbb6e99b71f22]::span_encoding::Span>
  20:     0x7f24f936ae14 - rustc_middle[d56cef6af7a8b1f3]::util::bug::span_bug_fmt::<rustc_span[ddffbb6e99b71f22]::span_encoding::Span>
  21:     0x7f24f70b48a6 - <rustc_infer[72326066f9e32db8]::infer::region_constraints::RegionConstraintCollector>::make_eqregion
  22:     0x7f24f6f5e31b - rustc_middle[d56cef6af7a8b1f3]::ty::relate::super_relate_tys::<rustc_infer[72326066f9e32db8]::infer::equate::Equate>
  23:     0x7f24f6dbde0a - <rustc_infer[72326066f9e32db8]::infer::equate::Equate as rustc_middle[d56cef6af7a8b1f3]::ty::relate::TypeRelation>::tys
  24:     0x7f24f7805490 - <rustc_infer[72326066f9e32db8]::infer::at::At>::eq::<rustc_middle[d56cef6af7a8b1f3]::ty::Ty>
  25:     0x7f24f926c4f1 - <rustc_infer[72326066f9e32db8]::infer::InferCtxt>::can_eq::<rustc_middle[d56cef6af7a8b1f3]::ty::Ty>
  26:     0x7f24f927210d - <rustc_infer[72326066f9e32db8]::infer::InferCtxt as rustc_trait_selection[7879cd7b7694ee64]::traits::error_reporting::suggestions::InferCtxtExt>::suggest_dereferences
  27:     0x7f24f928afde - <rustc_infer[72326066f9e32db8]::infer::InferCtxt as rustc_trait_selection[7879cd7b7694ee64]::traits::error_reporting::InferCtxtExt>::report_selection_error
  28:     0x7f24f9294c3d - <rustc_infer[72326066f9e32db8]::infer::InferCtxt as rustc_trait_selection[7879cd7b7694ee64]::traits::error_reporting::InferCtxtPrivExt>::report_fulfillment_error
  29:     0x7f24f92878ca - <rustc_infer[72326066f9e32db8]::infer::InferCtxt as rustc_trait_selection[7879cd7b7694ee64]::traits::error_reporting::InferCtxtExt>::report_fulfillment_errors
  30:     0x7f24f706bafe - <rustc_typeck[28d91abb0f1e20ad]::check::fn_ctxt::FnCtxt>::check_argument_types
  31:     0x7f24f6fccd99 - <rustc_typeck[28d91abb0f1e20ad]::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  32:     0x7f24f7068543 - <rustc_typeck[28d91abb0f1e20ad]::check::fn_ctxt::FnCtxt>::check_argument_types
  33:     0x7f24f700c648 - <rustc_typeck[28d91abb0f1e20ad]::check::fn_ctxt::FnCtxt>::check_call
  34:     0x7f24f6fcb9b4 - <rustc_typeck[28d91abb0f1e20ad]::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  35:     0x7f24f703e942 - <rustc_typeck[28d91abb0f1e20ad]::check::fn_ctxt::FnCtxt>::check_match
  36:     0x7f24f6fccfaa - <rustc_typeck[28d91abb0f1e20ad]::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  37:     0x7f24f6fcbc6d - <rustc_typeck[28d91abb0f1e20ad]::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  38:     0x7f24f6fcbc6d - <rustc_typeck[28d91abb0f1e20ad]::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  39:     0x7f24f70065f7 - <rustc_typeck[28d91abb0f1e20ad]::check::fn_ctxt::FnCtxt>::check_block_with_expected
  40:     0x7f24f6fcbb1e - <rustc_typeck[28d91abb0f1e20ad]::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  41:     0x7f24f7a8d6ed - <rustc_typeck[28d91abb0f1e20ad]::check::fn_ctxt::FnCtxt>::check_return_expr
  42:     0x7f24f7a8a6c7 - rustc_typeck[28d91abb0f1e20ad]::check::check::check_fn
  43:     0x7f24f7a7d8a9 - <rustc_infer[72326066f9e32db8]::infer::InferCtxtBuilder>::enter::<&rustc_middle[d56cef6af7a8b1f3]::ty::context::TypeckResults, <rustc_typeck[28d91abb0f1e20ad]::check::inherited::InheritedBuilder>::enter<rustc_typeck[28d91abb0f1e20ad]::check::typeck_with_fallback<rustc_typeck[28d91abb0f1e20ad]::check::typeck::{closure#0}>::{closure#1}, &rustc_middle[d56cef6af7a8b1f3]::ty::context::TypeckResults>::{closure#0}>
  44:     0x7f24f7a7b324 - rustc_typeck[28d91abb0f1e20ad]::check::typeck
  45:     0x7f24f7b0629d - <rustc_query_system[55191815e5fa4f71]::dep_graph::graph::DepGraph<rustc_middle[d56cef6af7a8b1f3]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[d56cef6af7a8b1f3]::ty::context::TyCtxt, rustc_span[ddffbb6e99b71f22]::def_id::LocalDefId, &rustc_middle[d56cef6af7a8b1f3]::ty::context::TypeckResults>
  46:     0x7f24f7afefb0 - rustc_query_system[55191815e5fa4f71]::query::plumbing::try_execute_query::<rustc_query_impl[349896560ef1ad2e]::plumbing::QueryCtxt, rustc_query_system[55191815e5fa4f71]::query::caches::DefaultCache<rustc_span[ddffbb6e99b71f22]::def_id::LocalDefId, &rustc_middle[d56cef6af7a8b1f3]::ty::context::TypeckResults>>
  47:     0x7f24f83be938 - <rustc_query_impl[349896560ef1ad2e]::Queries as rustc_middle[d56cef6af7a8b1f3]::ty::query::QueryEngine>::typeck
  48:     0x7f24f819983b - rustc_data_structures[e60caa46da70036b]::sync::par_for_each_in::<&[rustc_span[ddffbb6e99b71f22]::def_id::LocalDefId], <rustc_middle[d56cef6af7a8b1f3]::hir::map::Map>::par_body_owners<rustc_typeck[28d91abb0f1e20ad]::check::typeck_item_bodies::{closure#0}>::{closure#0}>
  49:     0x7f24f81995fb - <rustc_middle[d56cef6af7a8b1f3]::hir::map::Map>::par_body_owners::<rustc_typeck[28d91abb0f1e20ad]::check::typeck_item_bodies::{closure#0}>
  50:     0x7f24f819954c - rustc_typeck[28d91abb0f1e20ad]::check::typeck_item_bodies
  51:     0x7f24f80ec175 - <rustc_query_system[55191815e5fa4f71]::dep_graph::graph::DepGraph<rustc_middle[d56cef6af7a8b1f3]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[d56cef6af7a8b1f3]::ty::context::TyCtxt, (), ()>
  52:     0x7f24f80eb21f - rustc_query_system[55191815e5fa4f71]::query::plumbing::try_execute_query::<rustc_query_impl[349896560ef1ad2e]::plumbing::QueryCtxt, rustc_query_system[55191815e5fa4f71]::query::caches::DefaultCache<(), ()>>
  53:     0x7f24f80eac51 - rustc_query_system[55191815e5fa4f71]::query::plumbing::get_query::<rustc_query_impl[349896560ef1ad2e]::queries::typeck_item_bodies, rustc_query_impl[349896560ef1ad2e]::plumbing::QueryCtxt>
  54:     0x7f24f7e8ba8f - <rustc_session[9f308b2a826753c8]::session::Session>::time::<(), rustc_typeck[28d91abb0f1e20ad]::check_crate::{closure#7}>
  55:     0x7f24f7e8b54f - rustc_typeck[28d91abb0f1e20ad]::check_crate
  56:     0x7f24f7e8af67 - rustc_interface[b9288b4ecc31d2b]::passes::analysis
  57:     0x7f24f823fe02 - <rustc_query_system[55191815e5fa4f71]::dep_graph::graph::DepGraph<rustc_middle[d56cef6af7a8b1f3]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[d56cef6af7a8b1f3]::ty::context::TyCtxt, (), core[dc932bd71e0cd631]::result::Result<(), rustc_errors[b9540f85d88fac40]::ErrorGuaranteed>>
  58:     0x7f24f823f587 - rustc_query_system[55191815e5fa4f71]::query::plumbing::try_execute_query::<rustc_query_impl[349896560ef1ad2e]::plumbing::QueryCtxt, rustc_query_system[55191815e5fa4f71]::query::caches::DefaultCache<(), core[dc932bd71e0cd631]::result::Result<(), rustc_errors[b9540f85d88fac40]::ErrorGuaranteed>>>
  59:     0x7f24f823f07e - rustc_query_system[55191815e5fa4f71]::query::plumbing::get_query::<rustc_query_impl[349896560ef1ad2e]::queries::analysis, rustc_query_impl[349896560ef1ad2e]::plumbing::QueryCtxt>
  60:     0x7f24f7beb65d - <rustc_interface[b9288b4ecc31d2b]::passes::QueryContext>::enter::<rustc_driver[4d9024b7109a74ec]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[dc932bd71e0cd631]::result::Result<(), rustc_errors[b9540f85d88fac40]::ErrorGuaranteed>>
  61:     0x7f24f7bd66ae - <rustc_interface[b9288b4ecc31d2b]::interface::Compiler>::enter::<rustc_driver[4d9024b7109a74ec]::run_compiler::{closure#1}::{closure#2}, core[dc932bd71e0cd631]::result::Result<core[dc932bd71e0cd631]::option::Option<rustc_interface[b9288b4ecc31d2b]::queries::Linker>, rustc_errors[b9540f85d88fac40]::ErrorGuaranteed>>
  62:     0x7f24f7bd21bc - rustc_span[ddffbb6e99b71f22]::with_source_map::<core[dc932bd71e0cd631]::result::Result<(), rustc_errors[b9540f85d88fac40]::ErrorGuaranteed>, rustc_interface[b9288b4ecc31d2b]::interface::create_compiler_and_run<core[dc932bd71e0cd631]::result::Result<(), rustc_errors[b9540f85d88fac40]::ErrorGuaranteed>, rustc_driver[4d9024b7109a74ec]::run_compiler::{closure#1}>::{closure#1}>
  63:     0x7f24f7bd1ba2 - rustc_interface[b9288b4ecc31d2b]::interface::create_compiler_and_run::<core[dc932bd71e0cd631]::result::Result<(), rustc_errors[b9540f85d88fac40]::ErrorGuaranteed>, rustc_driver[4d9024b7109a74ec]::run_compiler::{closure#1}>
  64:     0x7f24f7bd0741 - <scoped_tls[32c4c3e7d82d6545]::ScopedKey<rustc_span[ddffbb6e99b71f22]::SessionGlobals>>::set::<rustc_interface[b9288b4ecc31d2b]::interface::run_compiler<core[dc932bd71e0cd631]::result::Result<(), rustc_errors[b9540f85d88fac40]::ErrorGuaranteed>, rustc_driver[4d9024b7109a74ec]::run_compiler::{closure#1}>::{closure#0}, core[dc932bd71e0cd631]::result::Result<(), rustc_errors[b9540f85d88fac40]::ErrorGuaranteed>>
  65:     0x7f24f7bd042f - std[e55f2e3b0b26feec]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[b9288b4ecc31d2b]::util::run_in_thread_pool_with_globals<rustc_interface[b9288b4ecc31d2b]::interface::run_compiler<core[dc932bd71e0cd631]::result::Result<(), rustc_errors[b9540f85d88fac40]::ErrorGuaranteed>, rustc_driver[4d9024b7109a74ec]::run_compiler::{closure#1}>::{closure#0}, core[dc932bd71e0cd631]::result::Result<(), rustc_errors[b9540f85d88fac40]::ErrorGuaranteed>>::{closure#0}, core[dc932bd71e0cd631]::result::Result<(), rustc_errors[b9540f85d88fac40]::ErrorGuaranteed>>
  66:     0x7f24f82dd139 - <<std[e55f2e3b0b26feec]::thread::Builder>::spawn_unchecked_<rustc_interface[b9288b4ecc31d2b]::util::run_in_thread_pool_with_globals<rustc_interface[b9288b4ecc31d2b]::interface::run_compiler<core[dc932bd71e0cd631]::result::Result<(), rustc_errors[b9540f85d88fac40]::ErrorGuaranteed>, rustc_driver[4d9024b7109a74ec]::run_compiler::{closure#1}>::{closure#0}, core[dc932bd71e0cd631]::result::Result<(), rustc_errors[b9540f85d88fac40]::ErrorGuaranteed>>::{closure#0}, core[dc932bd71e0cd631]::result::Result<(), rustc_errors[b9540f85d88fac40]::ErrorGuaranteed>>::{closure#1} as core[dc932bd71e0cd631]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  67:     0x7f24f5c7a8b3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h12cbced00fa20ada
                               at /rustc/015a824f2dffe32707fceb59c47effaf7b73486c/library/alloc/src/boxed.rs:1935:9
  68:     0x7f24f5c7a8b3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::he1f1327193714588
                               at /rustc/015a824f2dffe32707fceb59c47effaf7b73486c/library/alloc/src/boxed.rs:1935:9
  69:     0x7f24f5c7a8b3 - std::sys::unix::thread::Thread::new::thread_start::h4f7be77403771972
                               at /rustc/015a824f2dffe32707fceb59c47effaf7b73486c/library/std/src/sys/unix/thread.rs:108:17
  70:     0x7f24f5b32609 - start_thread
                               at /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:477:8
  71:     0x7f24f5a55133 - clone
                               at /build/glibc-SzIz7B/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  72:                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.65.0-nightly (015a824f2 2022-08-22) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [typeck] type-checking `main`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `damage`
```

Comment: Fun to see there is DeBruijn indexing going on, but I'm sure I'm not supposed to know that from simply using the compiler.

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_ASSIGN_START -->

<!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":"aliemjay"}$$TRIAGEBOT_ASSIGN_DATA_END -->

<!-- TRIAGEBOT_ASSIGN_END -->
<!-- TRIAGEBOT_END -->