Skip to content

rustc panics when analyzing closure in error condition (E0593) #128470

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
Natureshadow opened this issue Jul 31, 2024 · 2 comments
Closed

rustc panics when analyzing closure in error condition (E0593) #128470

Natureshadow opened this issue Jul 31, 2024 · 2 comments
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

@Natureshadow
Copy link

Natureshadow commented Jul 31, 2024

I found a bug in rustc when trying to compile the errornous program below.

The compiler does not crash anymore once I do one of the following:

  • Fix the E0593 error as suggested by rustc (the program won't compile then either due to a follow-up mistake, but rustc won't crash anymore)
  • Move the code in a direct impl without using the trait

Please note that the code as it is psoted here does not make much sense, especially the .enumerate().map() part, which looks like a no-op (if it were written correctly). The code was redruced to be as niminal as possible.

Code

use std::collections::HashSet;

#[derive(PartialEq, Eq, Hash, Clone, Debug)]
pub enum Triple {}

#[derive(PartialEq, Eq, Clone, Debug)]
pub struct Graph(HashSet<Triple>);

pub trait GraphRead {
    fn iter(&self) -> impl Iterator<Item = &Triple> + '_;

    fn matches(&self) -> impl Iterator<Item = &Triple> {
        self.iter().enumerate().map(|i, t| t)
    }
}

impl GraphRead for Graph {
    fn iter(&self) -> impl Iterator<Item = &Triple> + '_ {
        self.0.iter()
    }
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.75.0 (82e1608df 2023-12-21)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: x86_64-unknown-linux-gnu
release: 1.75.0
LLVM version: 17.0.6

Error output

error[E0593]: closure is expected to take a single 2-tuple as argument, but it takes 2 distinct arguments
  --> repr.rs:13:33
   |
13 |         self.iter().enumerate().map(|i, t| t)
   |                                 ^^^ ------ takes 2 distinct arguments
   |                                 |
   |                                 expected closure that takes a single 2-tuple as argument
   |
help: change the closure to accept a tuple instead of individual arguments
   |
13 |         self.iter().enumerate().map(|(i, t)| t)
   |               

<backtrace ommited, see below>

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.75.0 (82e1608df 2023-12-21) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [closure_typeinfo] finding symbols for captures of closure `GraphRead::matches::{closure#1}`
#1 [mir_borrowck] borrow-checking `GraphRead::matches::{closure#1}`
#2 [type_of_opaque] computing type of opaque `GraphRead::matches::{opaque#0}`
#3 [type_of] computing type of `GraphRead::matches::{opaque#0}`
#4 [check_mod_item_types] checking item types in top-level module
#5 [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 E0593`.

Backtrace

stack backtrace:
   0:     0x7f1e7dd2062c - std::backtrace_rs::backtrace::libunwind::trace::ha637c64ce894333a
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f1e7dd2062c - std::backtrace_rs::backtrace::trace_unsynchronized::h47f62dea28e0c88d
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f1e7dd2062c - std::sys_common::backtrace::_print_fmt::h9eef0abe20ede486
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f1e7dd2062c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hed7f999df88cc644
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f1e7dd73630 - core::fmt::rt::Argument::fmt::h1539a9308b8d058d
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/fmt/rt.rs:142:9
   5:     0x7f1e7dd73630 - core::fmt::write::h3a39390d8560d9c9
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f1e7dd1454f - std::io::Write::write_fmt::h5fc9997dfe05f882
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/io/mod.rs:1762:15
   7:     0x7f1e7dd20414 - std::sys_common::backtrace::_print::h894006fb5c6f3d45
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f1e7dd20414 - std::sys_common::backtrace::print::h23a2d212c6fff936
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f1e7dd230a7 - std::panicking::default_hook::{{closure}}::h8a1d2ee00185001a
  10:     0x7f1e7dd22e0f - std::panicking::default_hook::h6038f2eba384e475
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:292:9
  11:     0x7f1e7ab37190 - std[409886f6357001f0]::panicking::update_hook::<alloc[c1b021ad36e35877]::boxed::Box<rustc_driver_impl[7d23c5715ff089db]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f1e7dd237e8 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h1f8f335eaa9cfaee
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/alloc/src/boxed.rs:2021:9
  13:     0x7f1e7dd237e8 - std::panicking::rust_panic_with_hook::h2b5517d590cab22e
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:783:13
  14:     0x7f1e7dd2353e - std::panicking::begin_panic_handler::{{closure}}::h233112c06e0ef43e
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:657:13
  15:     0x7f1e7dd20af6 - std::sys_common::backtrace::__rust_end_short_backtrace::h6e893f24d7ebbff8
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:170:18
  16:     0x7f1e7dd232a2 - rust_begin_unwind
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:645:5
  17:     0x7f1e7dd6fd15 - core::panicking::panic_fmt::hbf0e066aabfa482c
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:72:14
  18:     0x7f1e7dd6fac3 - core::panicking::panic_display::h68e6012a1c287ca5
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:178:5
  19:     0x7f1e7dd6fac3 - core::panicking::panic_str::h1ca8e3b0d2d70f80
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:152:5
  20:     0x7f1e7dd6fac3 - core::option::expect_failed::h1ae4bac6b7606972
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/option.rs:1985:5
  21:     0x7f1e7d224460 - rustc_middle[aca4860da4e5a967]::ty::closure::closure_typeinfo.cold.0
  22:     0x7f1e7c76f526 - rustc_query_impl[664ae873a521fa7c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[664ae873a521fa7c]::query_impl::closure_typeinfo::dynamic_query::{closure#2}::{closure#0}, rustc_middle[aca4860da4e5a967]::query::erase::Erased<[u8; 64usize]>>
  23:     0x7f1e7c76f509 - <rustc_query_impl[664ae873a521fa7c]::query_impl::closure_typeinfo::dynamic_query::{closure#2} as core[21cdcf8e8af4c2d9]::ops::function::FnOnce<(rustc_middle[aca4860da4e5a967]::ty::context::TyCtxt, rustc_span[3d5dc97049ad8d50]::def_id::LocalDefId)>>::call_once
  24:     0x7f1e7c76ef0f - rustc_query_system[b5dcdc06a735d5f1]::query::plumbing::try_execute_query::<rustc_query_impl[664ae873a521fa7c]::DynamicConfig<rustc_query_system[b5dcdc06a735d5f1]::query::caches::VecCache<rustc_span[3d5dc97049ad8d50]::def_id::LocalDefId, rustc_middle[aca4860da4e5a967]::query::erase::Erased<[u8; 64usize]>>, false, false, false>, rustc_query_impl[664ae873a521fa7c]::plumbing::QueryCtxt, false>
  25:     0x7f1e7c76ec93 - rustc_query_impl[664ae873a521fa7c]::query_impl::closure_typeinfo::get_query_non_incr::__rust_end_short_backtrace
  26:     0x7f1e7c76e541 - <rustc_middle[aca4860da4e5a967]::ty::context::TyCtxt>::closure_captures
  27:     0x7f1e7cb7234f - rustc_borrowck[798173c66b163320]::do_mir_borrowck
  28:     0x7f1e7cb71397 - rustc_borrowck[798173c66b163320]::mir_borrowck
  29:     0x7f1e7cb70f57 - rustc_query_impl[664ae873a521fa7c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[664ae873a521fa7c]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[aca4860da4e5a967]::query::erase::Erased<[u8; 8usize]>>
  30:     0x7f1e7bf059ec - rustc_query_system[b5dcdc06a735d5f1]::query::plumbing::try_execute_query::<rustc_query_impl[664ae873a521fa7c]::DynamicConfig<rustc_query_system[b5dcdc06a735d5f1]::query::caches::VecCache<rustc_span[3d5dc97049ad8d50]::def_id::LocalDefId, rustc_middle[aca4860da4e5a967]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[664ae873a521fa7c]::plumbing::QueryCtxt, false>
  31:     0x7f1e7bf05610 - rustc_query_impl[664ae873a521fa7c]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7f1e7cc9ebc8 - <rustc_hir_analysis[eb447668a4654582]::collect::type_of::opaque::RpitConstraintChecker>::check
  33:     0x7f1e7a40ce35 - <rustc_hir_analysis[eb447668a4654582]::collect::type_of::opaque::RpitConstraintChecker as rustc_hir[3ec930a01a564d4c]::intravisit::Visitor>::visit_expr
  34:     0x7f1e7a40ce1b - <rustc_hir_analysis[eb447668a4654582]::collect::type_of::opaque::RpitConstraintChecker as rustc_hir[3ec930a01a564d4c]::intravisit::Visitor>::visit_expr
  35:     0x7f1e7ca792cc - rustc_hir_analysis[eb447668a4654582]::collect::type_of::type_of_opaque
  36:     0x7f1e7ca78ac9 - rustc_query_impl[664ae873a521fa7c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[664ae873a521fa7c]::query_impl::type_of_opaque::dynamic_query::{closure#2}::{closure#0}, rustc_middle[aca4860da4e5a967]::query::erase::Erased<[u8; 8usize]>>
  37:     0x7f1e7be5ff85 - rustc_query_system[b5dcdc06a735d5f1]::query::plumbing::try_execute_query::<rustc_query_impl[664ae873a521fa7c]::DynamicConfig<rustc_query_system[b5dcdc06a735d5f1]::query::caches::DefaultCache<rustc_span[3d5dc97049ad8d50]::def_id::DefId, rustc_middle[aca4860da4e5a967]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[664ae873a521fa7c]::plumbing::QueryCtxt, false>
  38:     0x7f1e7ccf4f9e - rustc_query_impl[664ae873a521fa7c]::query_impl::type_of_opaque::get_query_non_incr::__rust_end_short_backtrace
  39:     0x7f1e7bf0a83b - rustc_middle[aca4860da4e5a967]::query::plumbing::query_get_at::<rustc_query_system[b5dcdc06a735d5f1]::query::caches::DefaultCache<rustc_span[3d5dc97049ad8d50]::def_id::DefId, rustc_middle[aca4860da4e5a967]::query::erase::Erased<[u8; 8usize]>>>
  40:     0x7f1e792d8638 - rustc_hir_analysis[eb447668a4654582]::collect::type_of::type_of
  41:     0x7f1e7be60be9 - rustc_query_impl[664ae873a521fa7c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[664ae873a521fa7c]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[aca4860da4e5a967]::query::erase::Erased<[u8; 8usize]>>
  42:     0x7f1e7be5ff85 - rustc_query_system[b5dcdc06a735d5f1]::query::plumbing::try_execute_query::<rustc_query_impl[664ae873a521fa7c]::DynamicConfig<rustc_query_system[b5dcdc06a735d5f1]::query::caches::DefaultCache<rustc_span[3d5dc97049ad8d50]::def_id::DefId, rustc_middle[aca4860da4e5a967]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[664ae873a521fa7c]::plumbing::QueryCtxt, false>
  43:     0x7f1e7be5fbab - rustc_query_impl[664ae873a521fa7c]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  44:     0x7f1e7bf0a83b - rustc_middle[aca4860da4e5a967]::query::plumbing::query_get_at::<rustc_query_system[b5dcdc06a735d5f1]::query::caches::DefaultCache<rustc_span[3d5dc97049ad8d50]::def_id::DefId, rustc_middle[aca4860da4e5a967]::query::erase::Erased<[u8; 8usize]>>>
  45:     0x7f1e7c9ec0b2 - rustc_hir_analysis[eb447668a4654582]::check::check::check_mod_item_types
  46:     0x7f1e7c9eaa79 - rustc_query_impl[664ae873a521fa7c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[664ae873a521fa7c]::query_impl::check_mod_item_types::dynamic_query::{closure#2}::{closure#0}, rustc_middle[aca4860da4e5a967]::query::erase::Erased<[u8; 0usize]>>
  47:     0x7f1e7c772708 - rustc_query_system[b5dcdc06a735d5f1]::query::plumbing::try_execute_query::<rustc_query_impl[664ae873a521fa7c]::DynamicConfig<rustc_query_system[b5dcdc06a735d5f1]::query::caches::DefaultCache<rustc_span[3d5dc97049ad8d50]::def_id::LocalModDefId, rustc_middle[aca4860da4e5a967]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[664ae873a521fa7c]::plumbing::QueryCtxt, false>
  48:     0x7f1e7c7720a1 - rustc_query_impl[664ae873a521fa7c]::query_impl::check_mod_item_types::get_query_non_incr::__rust_end_short_backtrace
  49:     0x7f1e7c28379b - rustc_hir_analysis[eb447668a4654582]::check_crate
  50:     0x7f1e7c48db59 - rustc_interface[fbb0cb4be6c0ba34]::passes::analysis
  51:     0x7f1e7c48d575 - rustc_query_impl[664ae873a521fa7c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[664ae873a521fa7c]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[aca4860da4e5a967]::query::erase::Erased<[u8; 1usize]>>
  52:     0x7f1e7c925766 - rustc_query_system[b5dcdc06a735d5f1]::query::plumbing::try_execute_query::<rustc_query_impl[664ae873a521fa7c]::DynamicConfig<rustc_query_system[b5dcdc06a735d5f1]::query::caches::SingleCache<rustc_middle[aca4860da4e5a967]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[664ae873a521fa7c]::plumbing::QueryCtxt, false>
  53:     0x7f1e7c925595 - rustc_query_impl[664ae873a521fa7c]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  54:     0x7f1e7cc07021 - rustc_interface[fbb0cb4be6c0ba34]::interface::run_compiler::<core[21cdcf8e8af4c2d9]::result::Result<(), rustc_span[3d5dc97049ad8d50]::ErrorGuaranteed>, rustc_driver_impl[7d23c5715ff089db]::run_compiler::{closure#1}>::{closure#0}
  55:     0x7f1e7cc0215b - std[409886f6357001f0]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[fbb0cb4be6c0ba34]::util::run_in_thread_with_globals<rustc_interface[fbb0cb4be6c0ba34]::interface::run_compiler<core[21cdcf8e8af4c2d9]::result::Result<(), rustc_span[3d5dc97049ad8d50]::ErrorGuaranteed>, rustc_driver_impl[7d23c5715ff089db]::run_compiler::{closure#1}>::{closure#0}, core[21cdcf8e8af4c2d9]::result::Result<(), rustc_span[3d5dc97049ad8d50]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[21cdcf8e8af4c2d9]::result::Result<(), rustc_span[3d5dc97049ad8d50]::ErrorGuaranteed>>
  56:     0x7f1e7cc01fb3 - <<std[409886f6357001f0]::thread::Builder>::spawn_unchecked_<rustc_interface[fbb0cb4be6c0ba34]::util::run_in_thread_with_globals<rustc_interface[fbb0cb4be6c0ba34]::interface::run_compiler<core[21cdcf8e8af4c2d9]::result::Result<(), rustc_span[3d5dc97049ad8d50]::ErrorGuaranteed>, rustc_driver_impl[7d23c5715ff089db]::run_compiler::{closure#1}>::{closure#0}, core[21cdcf8e8af4c2d9]::result::Result<(), rustc_span[3d5dc97049ad8d50]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[21cdcf8e8af4c2d9]::result::Result<(), rustc_span[3d5dc97049ad8d50]::ErrorGuaranteed>>::{closure#1} as core[21cdcf8e8af4c2d9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  57:     0x7f1e7dd2d6a5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc7eafaff61e32df9
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/alloc/src/boxed.rs:2007:9
  58:     0x7f1e7dd2d6a5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6ba4a5de48dd2304
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/alloc/src/boxed.rs:2007:9
  59:     0x7f1e7dd2d6a5 - std::sys::unix::thread::Thread::new::thread_start::he469335aef763e45
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys/unix/thread.rs:108:17
  60:     0x7f1e77c92ba2 - start_thread
  61:     0x7f1e77d1400c - clone3
  62:                0x0 - <unknown>

@Natureshadow Natureshadow 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 Jul 31, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 31, 2024
@matthiaskrgr
Copy link
Member

this is probably a duplicate of #117886 , should be fixed on latest nightly (and also latest stable?)

@Natureshadow
Copy link
Author

Oops, yep, I can confirm it doesn't happen with nightly, and indeed looks lilke a duplicate. Sorry!

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 2, 2024
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

4 participants