Skip to content

cannot relate bound region. When using mutable interface on one struct #109920

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

Closed
schleglermarcus opened this issue Apr 4, 2023 · 2 comments
Closed
Labels
C-bug Category: This is a bug. 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

@schleglermarcus
Copy link

schleglermarcus commented Apr 4, 2023

The compiler asked to submit this bug report.

Code

#[derive(Clone, Debug)]
pub enum Event {
    PressKey(i8),
}

struct Processor {
    event_handler: Box<dyn Fn(&Event, &dyn ResultPrinter) -> ()>,
}

impl Processor {
    fn handle(&self, ev: Event) {
        (self.event_handler)(&ev, self);
    }
}

trait ResultPrinter {
    fn print(&self, s: String);
}

impl ResultPrinter for Processor {
    fn print(&self, s: String) {
        println!("{}", s);
    }
}

pub fn main() {
    let func = |ev: &Event, p: & mut dyn ResultPrinter| match ev {
        Event::PressKey(num) => p.print(format!("pressed{}", num)),
    };
    let p = Processor {
        event_handler: Box::new(func),
    };
    p.handle(Event::PressKey(3));
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e82cbc051045d7e72c1b65ea352d54e2

Meta

rustc --version --verbose:

rustc 1.68.2 (9eb3afe9e 2023-03-27)
binary: rustc
commit-hash: 9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0
commit-date: 2023-03-27
host: x86_64-unknown-linux-gnu
release: 1.68.2
LLVM version: 15.0.6

Error output

error: internal compiler error: compiler/rustc_infer/src/infer/region_constraints/mod.rs:568:17: cannot relate bound region: ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed(DefId(0:31 ~ event_handle_compiler_crash[dd0d]::main::'_#1), '_) }) <= ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed(DefId(0:26 ~ event_handle_compiler_crash[dd0d]::Processor::'_#1), '_) })

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/compiler/rustc_errors/src/lib.rs:987:33
stack backtrace:
   0:     0x7f0b09c8e59a - std::backtrace_rs::backtrace::libunwind::trace::ha271a8a7e1f3d4ef
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f0b09c8e59a - std::backtrace_rs::backtrace::trace_unsynchronized::h85739da0352c791a
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f0b09c8e59a - std::sys_common::backtrace::_print_fmt::hbc6ebcfb2910b329
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f0b09c8e59a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he1c117e52d53614f
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f0b09cf039e - core::fmt::write::h25eb51b9526b8e0c
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/fmt/mod.rs:1213:17
   5:     0x7f0b09c7ebe5 - std::io::Write::write_fmt::ha9edec5fb1621933
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/io/mod.rs:1682:15
   6:     0x7f0b09c8e365 - std::sys_common::backtrace::_print::hf8657cd429fc3452
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f0b09c8e365 - std::sys_common::backtrace::print::h41b9b18ed86f86bd
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f0b09c9112f - std::panicking::default_hook::{{closure}}::h22a91871f4454152
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:267:22
   9:     0x7f0b09c90e6b - std::panicking::default_hook::h21ddc36de0cd4ae7
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:286:9
  10:     0x7f0b0cfe6324 - rustc_driver[70f63b52fde826b7]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f0b09c9196a - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h6f7e3c94ecc52e2f
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/boxed.rs:2002:9
  12:     0x7f0b09c9196a - std::panicking::rust_panic_with_hook::h5059419d6d59b3d0
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:692:13
  13:     0x7f0b0d2a1f81 - std[f8b79e573431a86c]::panicking::begin_panic::<rustc_errors[53e74ce803854a4d]::ExplicitBug>::{closure#0}
  14:     0x7f0b0d29a8d6 - std[f8b79e573431a86c]::sys_common::backtrace::__rust_end_short_backtrace::<std[f8b79e573431a86c]::panicking::begin_panic<rustc_errors[53e74ce803854a4d]::ExplicitBug>::{closure#0}, !>
  15:     0x7f0b0d32ada6 - std[f8b79e573431a86c]::panicking::begin_panic::<rustc_errors[53e74ce803854a4d]::ExplicitBug>
  16:     0x7f0b0d32ad96 - std[f8b79e573431a86c]::panic::panic_any::<rustc_errors[53e74ce803854a4d]::ExplicitBug>
  17:     0x7f0b0d3296c2 - <rustc_errors[53e74ce803854a4d]::HandlerInner>::span_bug::<rustc_span[7c23fb27ec020b97]::span_encoding::Span, &alloc[b346c7f99e9347e5]::string::String>
  18:     0x7f0b0d329567 - <rustc_errors[53e74ce803854a4d]::Handler>::span_bug::<rustc_span[7c23fb27ec020b97]::span_encoding::Span, &alloc[b346c7f99e9347e5]::string::String>
  19:     0x7f0b0d2deacb - rustc_middle[6dfce017f6b7786d]::util::bug::opt_span_bug_fmt::<rustc_span[7c23fb27ec020b97]::span_encoding::Span>::{closure#0}
  20:     0x7f0b0d2deb1a - rustc_middle[6dfce017f6b7786d]::ty::context::tls::with_opt::<rustc_middle[6dfce017f6b7786d]::util::bug::opt_span_bug_fmt<rustc_span[7c23fb27ec020b97]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f0b0d2ddbda - rustc_middle[6dfce017f6b7786d]::ty::context::tls::with_context_opt::<rustc_middle[6dfce017f6b7786d]::ty::context::tls::with_opt<rustc_middle[6dfce017f6b7786d]::util::bug::opt_span_bug_fmt<rustc_span[7c23fb27ec020b97]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f0b0d2ddb06 - rustc_middle[6dfce017f6b7786d]::util::bug::opt_span_bug_fmt::<rustc_span[7c23fb27ec020b97]::span_encoding::Span>
  23:     0x7f0b0d2ddac4 - rustc_middle[6dfce017f6b7786d]::util::bug::span_bug_fmt::<rustc_span[7c23fb27ec020b97]::span_encoding::Span>
  24:     0x7f0b0af71604 - <rustc_middle[6dfce017f6b7786d]::ty::sty::Region as rustc_middle[6dfce017f6b7786d]::ty::relate::Relate>::relate::<rustc_infer[83c7bda8c7ffae41]::infer::equate::Equate>
  25:     0x7f0b0af6cf48 - rustc_middle[6dfce017f6b7786d]::ty::relate::super_relate_tys::<rustc_infer[83c7bda8c7ffae41]::infer::equate::Equate>
  26:     0x7f0b0af698be - <rustc_infer[83c7bda8c7ffae41]::infer::equate::Equate as rustc_middle[6dfce017f6b7786d]::ty::relate::TypeRelation>::tys
  27:     0x7f0b0b7fbdb3 - <rustc_infer[83c7bda8c7ffae41]::infer::InferCtxt>::commit_if_ok::<rustc_infer[83c7bda8c7ffae41]::infer::InferOk<()>, rustc_middle[6dfce017f6b7786d]::ty::error::TypeError, <rustc_infer[83c7bda8c7ffae41]::infer::at::Trace>::eq<rustc_middle[6dfce017f6b7786d]::ty::Ty>::{closure#0}>
  28:     0x7f0b0b7fbca6 - <rustc_infer[83c7bda8c7ffae41]::infer::at::At>::eq::<rustc_middle[6dfce017f6b7786d]::ty::Ty>
  29:     0x7f0b0dbc439e - <rustc_infer[83c7bda8c7ffae41]::infer::InferCtxt>::can_eq::<rustc_middle[6dfce017f6b7786d]::ty::Ty>
  30:     0x7f0b0dba71d2 - rustc_trait_selection[d385e741675330b5]::traits::error_reporting::suggestions::hint_missing_borrow
  31:     0x7f0b0dc4a934 - <rustc_infer[83c7bda8c7ffae41]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[d385e741675330b5]::traits::error_reporting::suggestions::TypeErrCtxtExt>::report_closure_arg_mismatch
  32:     0x7f0b0dc5a788 - <rustc_infer[83c7bda8c7ffae41]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[d385e741675330b5]::traits::error_reporting::TypeErrCtxtExt>::report_selection_error
  33:     0x7f0b0dc64167 - <rustc_infer[83c7bda8c7ffae41]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[d385e741675330b5]::traits::error_reporting::InferCtxtPrivExt>::report_fulfillment_error
  34:     0x7f0b0dc577cf - <rustc_infer[83c7bda8c7ffae41]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[d385e741675330b5]::traits::error_reporting::TypeErrCtxtExt>::report_fulfillment_errors
  35:     0x7f0b0b1e2b93 - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::demand_coerce
  36:     0x7f0b0b1ab689 - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_decl
  37:     0x7f0b0b1a8773 - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_block_with_expected
  38:     0x7f0b0b172d3c - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  39:     0x7f0b0b10d8d1 - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_return_expr
  40:     0x7f0b0b104802 - rustc_hir_typeck[698e9809084ff9ec]::check::check_fn
  41:     0x7f0b0b0ed0be - rustc_hir_typeck[698e9809084ff9ec]::typeck
  42:     0x7f0b0b0de797 - <rustc_query_system[59807289ca97d521]::dep_graph::graph::DepGraph<rustc_middle[6dfce017f6b7786d]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[6dfce017f6b7786d]::ty::context::TyCtxt, rustc_span[7c23fb27ec020b97]::def_id::LocalDefId, &rustc_middle[6dfce017f6b7786d]::ty::typeck_results::TypeckResults>
  43:     0x7f0b0b0d62eb - rustc_query_system[59807289ca97d521]::query::plumbing::try_execute_query::<rustc_query_impl[81153385010d7886]::queries::typeck, rustc_query_impl[81153385010d7886]::plumbing::QueryCtxt>
  44:     0x7f0b0c7f7f6d - rustc_query_system[59807289ca97d521]::query::plumbing::force_query::<rustc_query_impl[81153385010d7886]::queries::typeck, rustc_query_impl[81153385010d7886]::plumbing::QueryCtxt, rustc_middle[6dfce017f6b7786d]::dep_graph::dep_node::DepKind>
  45:     0x7f0b0c7f7e70 - rustc_query_impl[81153385010d7886]::plumbing::force_from_dep_node::<rustc_query_impl[81153385010d7886]::queries::typeck>
  46:     0x7f0b0b0608b2 - <rustc_query_system[59807289ca97d521]::dep_graph::graph::DepGraph<rustc_middle[6dfce017f6b7786d]::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl[81153385010d7886]::plumbing::QueryCtxt>
  47:     0x7f0b0b060621 - <rustc_query_system[59807289ca97d521]::dep_graph::graph::DepGraph<rustc_middle[6dfce017f6b7786d]::dep_graph::dep_node::DepKind>>::try_mark_green::<rustc_query_impl[81153385010d7886]::plumbing::QueryCtxt>
  48:     0x7f0b0c5679bf - rustc_query_system[59807289ca97d521]::query::plumbing::try_load_from_disk_and_cache_in_memory::<rustc_query_impl[81153385010d7886]::queries::typeck_item_bodies, rustc_query_impl[81153385010d7886]::plumbing::QueryCtxt>
  49:     0x7f0b0c566ae7 - rustc_query_system[59807289ca97d521]::query::plumbing::try_execute_query::<rustc_query_impl[81153385010d7886]::queries::typeck_item_bodies, rustc_query_impl[81153385010d7886]::plumbing::QueryCtxt>
  50:     0x7f0b0c99ed5b - <rustc_query_impl[81153385010d7886]::Queries as rustc_middle[6dfce017f6b7786d]::ty::query::QueryEngine>::typeck_item_bodies
  51:     0x7f0b0b47bee2 - <rustc_session[cd7c78827427c6d6]::session::Session>::time::<(), rustc_hir_analysis[651175ae4d1746c1]::check_crate::{closure#7}>
  52:     0x7f0b0b47b352 - rustc_hir_analysis[651175ae4d1746c1]::check_crate
  53:     0x7f0b0b47afab - rustc_interface[698bad460dbd68d3]::passes::analysis
  54:     0x7f0b0c711f76 - <rustc_query_system[59807289ca97d521]::dep_graph::graph::DepGraph<rustc_middle[6dfce017f6b7786d]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[6dfce017f6b7786d]::ty::context::TyCtxt, (), core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>>
  55:     0x7f0b0c711131 - rustc_query_system[59807289ca97d521]::query::plumbing::try_execute_query::<rustc_query_impl[81153385010d7886]::queries::analysis, rustc_query_impl[81153385010d7886]::plumbing::QueryCtxt>
  56:     0x7f0b0c99b60a - <rustc_query_impl[81153385010d7886]::Queries as rustc_middle[6dfce017f6b7786d]::ty::query::QueryEngine>::analysis
  57:     0x7f0b0c1c7010 - <rustc_interface[698bad460dbd68d3]::passes::QueryContext>::enter::<rustc_driver[70f63b52fde826b7]::run_compiler::{closure#1}::{closure#2}::{closure#2}, core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>>
  58:     0x7f0b0c1c4a84 - rustc_span[7c23fb27ec020b97]::with_source_map::<core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>, rustc_interface[698bad460dbd68d3]::interface::run_compiler<core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>, rustc_driver[70f63b52fde826b7]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  59:     0x7f0b0c1bd2d4 - <scoped_tls[1044df3f3db9be03]::ScopedKey<rustc_span[7c23fb27ec020b97]::SessionGlobals>>::set::<rustc_interface[698bad460dbd68d3]::interface::run_compiler<core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>, rustc_driver[70f63b52fde826b7]::run_compiler::{closure#1}>::{closure#0}, core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>>
  60:     0x7f0b0c1bc9d2 - std[f8b79e573431a86c]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[698bad460dbd68d3]::util::run_in_thread_pool_with_globals<rustc_interface[698bad460dbd68d3]::interface::run_compiler<core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>, rustc_driver[70f63b52fde826b7]::run_compiler::{closure#1}>::{closure#0}, core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>>
  61:     0x7f0b0c1bc77a - <<std[f8b79e573431a86c]::thread::Builder>::spawn_unchecked_<rustc_interface[698bad460dbd68d3]::util::run_in_thread_pool_with_globals<rustc_interface[698bad460dbd68d3]::interface::run_compiler<core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>, rustc_driver[70f63b52fde826b7]::run_compiler::{closure#1}>::{closure#0}, core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>>::{closure#1} as core[1d432356d8e1e9f1]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  62:     0x7f0b09c9b823 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3205ec2d7fc232c5
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/boxed.rs:1988:9
  63:     0x7f0b09c9b823 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3bb5daec8177f56b
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/boxed.rs:1988:9
  64:     0x7f0b09c9b823 - std::sys::unix::thread::Thread::new::thread_start::had7b8061e306bb5c
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys/unix/thread.rs:108:17
  65:     0x7f0b099b9b43 - start_thread
                               at ./nptl/./nptl/pthread_create.c:442:8
  66:     0x7f0b09a4ba00 - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  67:                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.2 (9eb3afe9e 2023-03-27) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -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 `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 `tricks`
[Finished running. Exit status: 101]

On the playground, the beta version catches this pattern.

@schleglermarcus schleglermarcus added C-bug Category: This is a bug. 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. labels Apr 4, 2023
@schleglermarcus schleglermarcus changed the title cannot relate bound region. When using multiple interfaces on one struct cannot relate bound region. When using mutable interface on one struct Apr 4, 2023
@lqd
Copy link
Member

lqd commented Apr 4, 2023

I believe this has already been fixed on nightly and beta.

@jyn514
Copy link
Member

jyn514 commented Apr 4, 2023

Duplicate of #109361

@jyn514 jyn514 marked this as a duplicate of #109361 Apr 4, 2023
@jyn514 jyn514 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 4, 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. 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

No branches or pull requests

3 participants