Skip to content

Compiler panicked while solving a Project Euler problem #110447

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
tfpf opened this issue Apr 17, 2023 · 3 comments
Closed

Compiler panicked while solving a Project Euler problem #110447

tfpf opened this issue Apr 17, 2023 · 3 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tfpf
Copy link

tfpf commented Apr 17, 2023

Code

fn score((idx, name): (usize, &str)) -> usize
{
    let sum: usize = name.chars().map(|c| c as usize - 64).sum();
    sum * (idx + 1)
}

fn main()
{
    let exe = std::env::current_exe().unwrap();
    let directory = exe.parent().unwrap();
    let fname = directory.join("names.txt");
    let contents = std::fs::read_to_string(&fname).unwrap();

    let mut names: Vec<&str> = contents.split(",").map(|s| &s[1..s.len() - 1]).collect();
    names.sort();
    let result = names.iter().enumerate().map(score).sum();
}

You can get the file names.txt from problem 22 of Project Euler, but that isn't required, because the panic occurs while compiling.

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

No error output. It panicked upon issuing the compile command.

rustc -C opt-level=2 -C strip=debuginfo -o names_scores names_scores.rs
Backtrace

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:7 ~ names_scores[6770]::score::'_), '_) }) <= '_#45r

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/compiler/rustc_errors/src/lib.rs:987:33
stack backtrace:
   0:     0x7f88a77bd59a - std::backtrace_rs::backtrace::libunwind::trace::ha271a8a7e1f3d4ef
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f88a77bd59a - std::backtrace_rs::backtrace::trace_unsynchronized::h85739da0352c791a
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f88a77bd59a - std::sys_common::backtrace::_print_fmt::hbc6ebcfb2910b329
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f88a77bd59a - <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:     0x7f88a781f39e - core::fmt::write::h25eb51b9526b8e0c
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/fmt/mod.rs:1213:17
   5:     0x7f88a77adbe5 - std::io::Write::write_fmt::ha9edec5fb1621933
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/io/mod.rs:1682:15
   6:     0x7f88a77bd365 - std::sys_common::backtrace::_print::hf8657cd429fc3452
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f88a77bd365 - std::sys_common::backtrace::print::h41b9b18ed86f86bd
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f88a77c012f - std::panicking::default_hook::{{closure}}::h22a91871f4454152
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:267:22
   9:     0x7f88a77bfe6b - std::panicking::default_hook::h21ddc36de0cd4ae7
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:286:9
  10:     0x7f88aab10324 - rustc_driver[70f63b52fde826b7]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f88a77c096a - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h6f7e3c94ecc52e2f
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/boxed.rs:2002:9
  12:     0x7f88a77c096a - std::panicking::rust_panic_with_hook::h5059419d6d59b3d0
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:692:13
  13:     0x7f88aadcbf81 - std[f8b79e573431a86c]::panicking::begin_panic::<rustc_errors[53e74ce803854a4d]::ExplicitBug>::{closure#0}
  14:     0x7f88aadc48d6 - std[f8b79e573431a86c]::sys_common::backtrace::__rust_end_short_backtrace::<std[f8b79e573431a86c]::panicking::begin_panic<rustc_errors[53e74ce803854a4d]::ExplicitBug>::{closure#0}, !>
  15:     0x7f88aae54da6 - std[f8b79e573431a86c]::panicking::begin_panic::<rustc_errors[53e74ce803854a4d]::ExplicitBug>
  16:     0x7f88aae54d96 - std[f8b79e573431a86c]::panic::panic_any::<rustc_errors[53e74ce803854a4d]::ExplicitBug>
  17:     0x7f88aae536c2 - <rustc_errors[53e74ce803854a4d]::HandlerInner>::span_bug::<rustc_span[7c23fb27ec020b97]::span_encoding::Span, &alloc[b346c7f99e9347e5]::string::String>
  18:     0x7f88aae53567 - <rustc_errors[53e74ce803854a4d]::Handler>::span_bug::<rustc_span[7c23fb27ec020b97]::span_encoding::Span, &alloc[b346c7f99e9347e5]::string::String>
  19:     0x7f88aae08acb - rustc_middle[6dfce017f6b7786d]::util::bug::opt_span_bug_fmt::<rustc_span[7c23fb27ec020b97]::span_encoding::Span>::{closure#0}
  20:     0x7f88aae08b1a - 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:     0x7f88aae07bda - 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:     0x7f88aae07b06 - rustc_middle[6dfce017f6b7786d]::util::bug::opt_span_bug_fmt::<rustc_span[7c23fb27ec020b97]::span_encoding::Span>
  23:     0x7f88aae07ac4 - rustc_middle[6dfce017f6b7786d]::util::bug::span_bug_fmt::<rustc_span[7c23fb27ec020b97]::span_encoding::Span>
  24:     0x7f88a8a9b604 - <rustc_middle[6dfce017f6b7786d]::ty::sty::Region as rustc_middle[6dfce017f6b7786d]::ty::relate::Relate>::relate::<rustc_infer[83c7bda8c7ffae41]::infer::equate::Equate>
  25:     0x7f88a8a95f86 - rustc_middle[6dfce017f6b7786d]::ty::relate::super_relate_tys::<rustc_infer[83c7bda8c7ffae41]::infer::equate::Equate>
  26:     0x7f88a8a938be - <rustc_infer[83c7bda8c7ffae41]::infer::equate::Equate as rustc_middle[6dfce017f6b7786d]::ty::relate::TypeRelation>::tys
  27:     0x7f88a8a9676a - rustc_middle[6dfce017f6b7786d]::ty::relate::super_relate_tys::<rustc_infer[83c7bda8c7ffae41]::infer::equate::Equate>
  28:     0x7f88a8a938be - <rustc_infer[83c7bda8c7ffae41]::infer::equate::Equate as rustc_middle[6dfce017f6b7786d]::ty::relate::TypeRelation>::tys
  29:     0x7f88a9325db3 - <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}>
  30:     0x7f88a9325ca6 - <rustc_infer[83c7bda8c7ffae41]::infer::at::At>::eq::<rustc_middle[6dfce017f6b7786d]::ty::Ty>
  31:     0x7f88ab6ee39e - <rustc_infer[83c7bda8c7ffae41]::infer::InferCtxt>::can_eq::<rustc_middle[6dfce017f6b7786d]::ty::Ty>
  32:     0x7f88ab6d11d2 - rustc_trait_selection[d385e741675330b5]::traits::error_reporting::suggestions::hint_missing_borrow
  33:     0x7f88ab774934 - <rustc_infer[83c7bda8c7ffae41]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[d385e741675330b5]::traits::error_reporting::suggestions::TypeErrCtxtExt>::report_closure_arg_mismatch
  34:     0x7f88ab784788 - <rustc_infer[83c7bda8c7ffae41]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[d385e741675330b5]::traits::error_reporting::TypeErrCtxtExt>::report_selection_error
  35:     0x7f88ab78e167 - <rustc_infer[83c7bda8c7ffae41]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[d385e741675330b5]::traits::error_reporting::InferCtxtPrivExt>::report_fulfillment_error
  36:     0x7f88ab7817cf - <rustc_infer[83c7bda8c7ffae41]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[d385e741675330b5]::traits::error_reporting::TypeErrCtxtExt>::report_fulfillment_errors
  37:     0x7f88a8d17535 - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_argument_types
  38:     0x7f88a8c9ea92 - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  39:     0x7f88a8c9cd87 - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  40:     0x7f88a8cd566e - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_decl
  41:     0x7f88a8cd2773 - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_block_with_expected
  42:     0x7f88a8c9cd3c - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  43:     0x7f88a8c378d1 - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_return_expr
  44:     0x7f88a8c2e802 - rustc_hir_typeck[698e9809084ff9ec]::check::check_fn
  45:     0x7f88a8c170be - rustc_hir_typeck[698e9809084ff9ec]::typeck
  46:     0x7f88a8bffda3 - rustc_query_system[59807289ca97d521]::query::plumbing::try_execute_query::<rustc_query_impl[81153385010d7886]::queries::typeck, rustc_query_impl[81153385010d7886]::plumbing::QueryCtxt>
  47:     0x7f88aa26d3cd - rustc_data_structures[560608da72c35763]::sync::par_for_each_in::<&[rustc_span[7c23fb27ec020b97]::def_id::LocalDefId], <rustc_middle[6dfce017f6b7786d]::hir::map::Map>::par_body_owners<rustc_hir_typeck[698e9809084ff9ec]::typeck_item_bodies::{closure#0}>::{closure#0}>
  48:     0x7f88aa26d173 - rustc_hir_typeck[698e9809084ff9ec]::typeck_item_bodies
  49:     0x7f88aa0909a2 - rustc_query_system[59807289ca97d521]::query::plumbing::try_execute_query::<rustc_query_impl[81153385010d7886]::queries::typeck_item_bodies, rustc_query_impl[81153385010d7886]::plumbing::QueryCtxt>
  50:     0x7f88aa4c8d5b - <rustc_query_impl[81153385010d7886]::Queries as rustc_middle[6dfce017f6b7786d]::ty::query::QueryEngine>::typeck_item_bodies
  51:     0x7f88a8fa5ee2 - <rustc_session[cd7c78827427c6d6]::session::Session>::time::<(), rustc_hir_analysis[651175ae4d1746c1]::check_crate::{closure#7}>
  52:     0x7f88a8fa5352 - rustc_hir_analysis[651175ae4d1746c1]::check_crate
  53:     0x7f88a8fa4fab - rustc_interface[698bad460dbd68d3]::passes::analysis
  54:     0x7f88aa23aeee - rustc_query_system[59807289ca97d521]::query::plumbing::try_execute_query::<rustc_query_impl[81153385010d7886]::queries::analysis, rustc_query_impl[81153385010d7886]::plumbing::QueryCtxt>
  55:     0x7f88aa4c560a - <rustc_query_impl[81153385010d7886]::Queries as rustc_middle[6dfce017f6b7786d]::ty::query::QueryEngine>::analysis
  56:     0x7f88a9cf1010 - <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>>
  57:     0x7f88a9ceea84 - 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}>
  58:     0x7f88a9ce72d4 - <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>>
  59:     0x7f88a9ce69d2 - 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>>
  60:     0x7f88a9ce677a - <<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}
  61:     0x7f88a77ca823 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3205ec2d7fc232c5
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/boxed.rs:1988:9
  62:     0x7f88a77ca823 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3bb5daec8177f56b
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/boxed.rs:1988:9
  63:     0x7f88a77ca823 - std::sys::unix::thread::Thread::new::thread_start::had7b8061e306bb5c
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys/unix/thread.rs:108:17
  64:     0x7f88a7549bb5 - <unknown>
  65:     0x7f88a75cbd90 - <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.2 (9eb3afe9e 2023-03-27) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=2 -C strip=debuginfo

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: aborting due to previous error

Beta/Nightly

This code does not compile on the beta and nightly versions, but does not result in a panic, either:

error[E0631]: type mismatch in function arguments
  --> 0001-0100/0022/names_scores.rs:16:47
   |
1  | fn score((idx, name): (usize, &str)) -> usize
   | --------------------------------------------- found signature defined here
...
16 |     let result = names.iter().enumerate().map(score).sum();
   |                                           --- ^^^^^ expected due to this
   |                                           |
   |                                           required by a bound introduced by this call
   |
   = note: expected function signature `fn((_, &&str)) -> _`
              found function signature `for<'a> fn((_, &'a str)) -> _`
note: required by a bound in `map`
  --> /rustc/f18236dcd3d8191c91aca0c4ef43e1e27b6bc0dc/library/core/src/iter/traits/iterator.rs:796:5

error[E0599]: the method `sum` exists for struct `Map<Enumerate<Iter<'_, &str>>, fn((usize, &str)) -> usize {score}>`, but its trait bounds were not satisfied
  --> 0001-0100/0022/names_scores.rs:16:54
   |
16 |     let result = names.iter().enumerate().map(score).sum();
   |                                                      ^^^ method cannot be called due to unsatisfied trait bounds
  --> /rustc/f18236dcd3d8191c91aca0c4ef43e1e27b6bc0dc/library/core/src/iter/adapters/map.rs:61:1
   |
   = note: doesn't satisfy `_: Iterator`
   |
   = note: the following trait bounds were not satisfied:
           `<for<'a> fn((usize, &'a str)) -> usize {score} as FnOnce<((usize, &&str),)>>::Output = _`
           which is required by `Map<Enumerate<std::slice::Iter<'_, &str>>, for<'a> fn((usize, &'a str)) -> usize {score}>: Iterator`
           `for<'a> fn((usize, &'a str)) -> usize {score}: FnMut<((usize, &&str),)>`
           which is required by `Map<Enumerate<std::slice::Iter<'_, &str>>, for<'a> fn((usize, &'a str)) -> usize {score}>: Iterator`
           `Map<Enumerate<std::slice::Iter<'_, &str>>, for<'a> fn((usize, &'a str)) -> usize {score}>: Iterator`
           which is required by `&mut Map<Enumerate<std::slice::Iter<'_, &str>>, for<'a> fn((usize, &'a str)) -> usize {score}>: Iterator`

error: aborting due to 2 previous errors

but the error message is not clear. The function signatures do match. Curiously, if I write:

    let result: usize = names.iter().enumerate().map(|(i, name)| score((i, name))).sum();

the compiler is fine with it.

@tfpf tfpf 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 17, 2023
@aDotInTheVoid
Copy link
Member

Minimized:

fn score(_: (usize, &str)) -> usize {
    0
}

fn main() {
    let mut names: Vec<&str> = vec![];
    let result = names.iter().enumerate().map(score);
}

On 1.42, this has a good error

error[E0631]: type mismatch in function arguments
 --> ./ice.rs:7:47
  |
1 | fn score(_: (usize, &str)) -> usize {
  | ----------------------------------- found signature of `for<'r> fn((usize, &'r str)) -> _`
...
7 |     let result = names.iter().enumerate().map(score);
  |                                               ^^^^^ expected signature of `fn((usize, &&str)) -> _`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0631`.

On 1.68.2, this ICE's

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:5 ~ ice[925a]::score::'_), '_) }) <= '_#11r

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/compiler/rustc_errors/src/lib.rs:987:33
stack backtrace:
   0:     0xffff79496140 - std::backtrace_rs::backtrace::libunwind::trace::hc7f75b32c0689d70
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0xffff79496140 - std::backtrace_rs::backtrace::trace_unsynchronized::h164689022fd6f73e
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0xffff79496140 - std::sys_common::backtrace::_print_fmt::he9484e79d39a3f7a
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:65:5
   3:     0xffff79496140 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5e6dff1da54ef98d
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:44:22
   4:     0xffff794ee000 - core::fmt::write::hc446e03b1e01cc30
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/fmt/mod.rs:1213:17
   5:     0xffff79488f50 - std::io::Write::write_fmt::h526cc884fdeb5eb2
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/io/mod.rs:1682:15
   6:     0xffff79495f4c - std::sys_common::backtrace::_print::h393dd98b7ebd466b
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:47:5
   7:     0xffff79495f4c - std::sys_common::backtrace::print::hebc7712091d53c41
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:34:9
   8:     0xffff79498928 - std::panicking::default_hook::{{closure}}::h39baab9c8bcc3210
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:267:22
   9:     0xffff7949866c - std::panicking::default_hook::he6636537b1f4983b
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:286:9
  10:     0xffff7a1ccc94 - rustc_driver[f25ea7069dadae60]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0xffff79499088 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hae11afcdab10a5eb
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/boxed.rs:2002:9
  12:     0xffff79499088 - std::panicking::rust_panic_with_hook::h2719e7603a56e8f6
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:692:13
  13:     0xffff7eb2bf5c - std[43bd97b51c4b7ccc]::panicking::begin_panic::<rustc_errors[8c811b1d8d2fea79]::ExplicitBug>::{closure#0}
  14:     0xffff7eb228f4 - std[43bd97b51c4b7ccc]::sys_common::backtrace::__rust_end_short_backtrace::<std[43bd97b51c4b7ccc]::panicking::begin_panic<rustc_errors[8c811b1d8d2fea79]::ExplicitBug>::{closure#0}, !>
  15:     0xffff7a0879f0 - std[43bd97b51c4b7ccc]::panicking::begin_panic::<rustc_errors[8c811b1d8d2fea79]::ExplicitBug>
  16:     0xffff7ebf5cf8 - std[43bd97b51c4b7ccc]::panic::panic_any::<rustc_errors[8c811b1d8d2fea79]::ExplicitBug>
  17:     0xffff7ebf30e4 - <rustc_errors[8c811b1d8d2fea79]::HandlerInner>::span_bug::<rustc_span[74d55c38045fab67]::span_encoding::Span, &alloc[7ce36d2166794c95]::string::String>
  18:     0xffff7ebf2f24 - <rustc_errors[8c811b1d8d2fea79]::Handler>::span_bug::<rustc_span[74d55c38045fab67]::span_encoding::Span, &alloc[7ce36d2166794c95]::string::String>
  19:     0xffff7eb83954 - rustc_middle[ca8436e622f06ed]::util::bug::opt_span_bug_fmt::<rustc_span[74d55c38045fab67]::span_encoding::Span>::{closure#0}
  20:     0xffff7eb83c50 - rustc_middle[ca8436e622f06ed]::ty::context::tls::with_opt::<rustc_middle[ca8436e622f06ed]::util::bug::opt_span_bug_fmt<rustc_span[74d55c38045fab67]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0xffff7eb81370 - rustc_middle[ca8436e622f06ed]::ty::context::tls::with_context_opt::<rustc_middle[ca8436e622f06ed]::ty::context::tls::with_opt<rustc_middle[ca8436e622f06ed]::util::bug::opt_span_bug_fmt<rustc_span[74d55c38045fab67]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0xffff7eb81330 - rustc_middle[ca8436e622f06ed]::util::bug::opt_span_bug_fmt::<rustc_span[74d55c38045fab67]::span_encoding::Span>
  23:     0xffff7a0834c0 - rustc_middle[ca8436e622f06ed]::util::bug::span_bug_fmt::<rustc_span[74d55c38045fab67]::span_encoding::Span>
  24:     0xffff7eb79b70 - <rustc_infer[c556dcc29778f58]::infer::region_constraints::RegionConstraintCollector>::make_subregion
  25:     0xffff7eb73c30 - <rustc_infer[c556dcc29778f58]::infer::region_constraints::RegionConstraintCollector>::make_eqregion
  26:     0xffff7eb8a640 - <rustc_infer[c556dcc29778f58]::infer::equate::Equate as rustc_middle[ca8436e622f06ed]::ty::relate::TypeRelation>::regions
  27:     0xffff7eb91590 - rustc_middle[ca8436e622f06ed]::ty::relate::super_relate_tys::<rustc_infer[c556dcc29778f58]::infer::equate::Equate>
  28:     0xffff7eb8dad8 - <rustc_infer[c556dcc29778f58]::infer::equate::Equate as rustc_middle[ca8436e622f06ed]::ty::relate::TypeRelation>::tys
  29:     0xffff7eb5d7a4 - <core[3d0f08c789d39c5d]::result::Result<rustc_middle[ca8436e622f06ed]::ty::Ty, rustc_middle[ca8436e622f06ed]::ty::error::TypeError> as rustc_type_ir[e8595ee35140abc6]::InternIteratorElement<rustc_middle[ca8436e622f06ed]::ty::Ty, rustc_middle[ca8436e622f06ed]::ty::Ty>>::intern_with::<core[3d0f08c789d39c5d]::iter::adapters::map::Map<core[3d0f08c789d39c5d]::iter::adapters::zip::Zip<core[3d0f08c789d39c5d]::iter::adapters::copied::Copied<core[3d0f08c789d39c5d]::slice::iter::Iter<rustc_middle[ca8436e622f06ed]::ty::Ty>>, core[3d0f08c789d39c5d]::iter::adapters::copied::Copied<core[3d0f08c789d39c5d]::slice::iter::Iter<rustc_middle[ca8436e622f06ed]::ty::Ty>>>, rustc_middle[ca8436e622f06ed]::ty::relate::super_relate_tys<rustc_infer[c556dcc29778f58]::infer::equate::Equate>::{closure#2}>, <rustc_middle[ca8436e622f06ed]::ty::context::TyCtxt>::mk_tup<core[3d0f08c789d39c5d]::iter::adapters::map::Map<core[3d0f08c789d39c5d]::iter::adapters::zip::Zip<core[3d0f08c789d39c5d]::iter::adapters::copied::Copied<core[3d0f08c789d39c5d]::slice::iter::Iter<rustc_middle[ca8436e622f06ed]::ty::Ty>>, core[3d0f08c789d39c5d]::iter::adapters::copied::Copied<core[3d0f08c789d39c5d]::slice::iter::Iter<rustc_middle[ca8436e622f06ed]::ty::Ty>>>, rustc_middle[ca8436e622f06ed]::ty::relate::super_relate_tys<rustc_infer[c556dcc29778f58]::infer::equate::Equate>::{closure#2}>>::{closure#0}>
  30:     0xffff7eb91660 - rustc_middle[ca8436e622f06ed]::ty::relate::super_relate_tys::<rustc_infer[c556dcc29778f58]::infer::equate::Equate>
  31:     0xffff7eb8dad8 - <rustc_infer[c556dcc29778f58]::infer::equate::Equate as rustc_middle[ca8436e622f06ed]::ty::relate::TypeRelation>::tys
  32:     0xffff7e962f40 - <rustc_infer[c556dcc29778f58]::infer::InferCtxt>::commit_if_ok::<rustc_infer[c556dcc29778f58]::infer::InferOk<()>, rustc_middle[ca8436e622f06ed]::ty::error::TypeError, <rustc_infer[c556dcc29778f58]::infer::at::Trace>::eq<rustc_middle[ca8436e622f06ed]::ty::Ty>::{closure#0}>
  33:     0xffff7e96c2cc - <rustc_infer[c556dcc29778f58]::infer::InferCtxt>::can_eq::<rustc_middle[ca8436e622f06ed]::ty::Ty>
  34:     0xffff7e9454a0 - rustc_trait_selection[edb54cbc6786beb4]::traits::error_reporting::suggestions::hint_missing_borrow
  35:     0xffff7ea2fd70 - <rustc_infer[c556dcc29778f58]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[edb54cbc6786beb4]::traits::error_reporting::suggestions::TypeErrCtxtExt>::report_closure_arg_mismatch
  36:     0xffff7ea3decc - <rustc_infer[c556dcc29778f58]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[edb54cbc6786beb4]::traits::error_reporting::TypeErrCtxtExt>::report_selection_error
  37:     0xffff7ea479b4 - <rustc_infer[c556dcc29778f58]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[edb54cbc6786beb4]::traits::error_reporting::InferCtxtPrivExt>::report_fulfillment_error
  38:     0xffff7ea38cdc - <rustc_infer[c556dcc29778f58]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[edb54cbc6786beb4]::traits::error_reporting::TypeErrCtxtExt>::report_fulfillment_errors
  39:     0xffff7cd6fd9c - <rustc_hir_typeck[f7a57d838252c150]::fn_ctxt::FnCtxt>::check_argument_types
  40:     0xffff7cd6f374 - <rustc_hir_typeck[f7a57d838252c150]::fn_ctxt::FnCtxt>::check_method_argument_types
  41:     0xffff7cdaef88 - <rustc_hir_typeck[f7a57d838252c150]::fn_ctxt::FnCtxt>::check_expr_kind
  42:     0xffff7cd630b8 - <rustc_hir_typeck[f7a57d838252c150]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  43:     0xffff7cd75cf0 - <rustc_hir_typeck[f7a57d838252c150]::fn_ctxt::FnCtxt>::check_decl
  44:     0xffff7cd76134 - <rustc_hir_typeck[f7a57d838252c150]::fn_ctxt::FnCtxt>::check_stmt
  45:     0xffff7cd76854 - <rustc_hir_typeck[f7a57d838252c150]::fn_ctxt::FnCtxt>::check_block_with_expected
  46:     0xffff7cdaa2c8 - <rustc_hir_typeck[f7a57d838252c150]::fn_ctxt::FnCtxt>::check_expr_kind
  47:     0xffff7cd630b8 - <rustc_hir_typeck[f7a57d838252c150]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  48:     0xffff7cd643b4 - <rustc_hir_typeck[f7a57d838252c150]::fn_ctxt::FnCtxt>::check_return_expr
  49:     0xffff7ce18a2c - rustc_hir_typeck[f7a57d838252c150]::check::check_fn
  50:     0xffff7ce4ec4c - rustc_hir_typeck[f7a57d838252c150]::typeck
  51:     0xffff7dff118c - rustc_query_system[ac9112f2d74ee54c]::query::plumbing::try_execute_query::<rustc_query_impl[d6b3b78047c3001e]::queries::typeck, rustc_query_impl[d6b3b78047c3001e]::plumbing::QueryCtxt>
  52:     0xffff7dd1e8a0 - <rustc_query_impl[d6b3b78047c3001e]::Queries as rustc_middle[ca8436e622f06ed]::ty::query::QueryEngine>::typeck
  53:     0xffff7ce0b0cc - rustc_data_structures[dae7e7f0f4779010]::sync::par_for_each_in::<&[rustc_span[74d55c38045fab67]::def_id::LocalDefId], <rustc_middle[ca8436e622f06ed]::hir::map::Map>::par_body_owners<rustc_hir_typeck[f7a57d838252c150]::typeck_item_bodies::{closure#0}>::{closure#0}>
  54:     0xffff7ce4cea0 - rustc_hir_typeck[f7a57d838252c150]::typeck_item_bodies
  55:     0xffff7df81fb4 - rustc_query_system[ac9112f2d74ee54c]::query::plumbing::try_execute_query::<rustc_query_impl[d6b3b78047c3001e]::queries::typeck_item_bodies, rustc_query_impl[d6b3b78047c3001e]::plumbing::QueryCtxt>
  56:     0xffff7dd1e798 - <rustc_query_impl[d6b3b78047c3001e]::Queries as rustc_middle[ca8436e622f06ed]::ty::query::QueryEngine>::typeck_item_bodies
  57:     0xffff7cfce5d0 - <rustc_session[bd5550e79ec773b]::session::Session>::time::<(), rustc_hir_analysis[a89ce9ead355c71d]::check_crate::{closure#7}>
  58:     0xffff7cf7cfb4 - rustc_hir_analysis[a89ce9ead355c71d]::check_crate
  59:     0xffff7a273e6c - rustc_interface[a23df4f4dba783b7]::passes::analysis
  60:     0xffff7dff376c - rustc_query_system[ac9112f2d74ee54c]::query::plumbing::try_execute_query::<rustc_query_impl[d6b3b78047c3001e]::queries::analysis, rustc_query_impl[d6b3b78047c3001e]::plumbing::QueryCtxt>
  61:     0xffff7dd1ba50 - <rustc_query_impl[d6b3b78047c3001e]::Queries as rustc_middle[ca8436e622f06ed]::ty::query::QueryEngine>::analysis
  62:     0xffff7a162bd0 - <rustc_interface[a23df4f4dba783b7]::passes::QueryContext>::enter::<rustc_driver[f25ea7069dadae60]::run_compiler::{closure#1}::{closure#2}::{closure#2}, core[3d0f08c789d39c5d]::result::Result<(), rustc_errors[8c811b1d8d2fea79]::ErrorGuaranteed>>
  63:     0xffff7a145414 - <rustc_interface[a23df4f4dba783b7]::queries::QueryResult<rustc_interface[a23df4f4dba783b7]::passes::QueryContext>>::enter::<core[3d0f08c789d39c5d]::result::Result<(), rustc_errors[8c811b1d8d2fea79]::ErrorGuaranteed>, rustc_driver[f25ea7069dadae60]::run_compiler::{closure#1}::{closure#2}::{closure#2}>
  64:     0xffff7a1a7a88 - rustc_span[74d55c38045fab67]::with_source_map::<core[3d0f08c789d39c5d]::result::Result<(), rustc_errors[8c811b1d8d2fea79]::ErrorGuaranteed>, rustc_interface[a23df4f4dba783b7]::interface::run_compiler<core[3d0f08c789d39c5d]::result::Result<(), rustc_errors[8c811b1d8d2fea79]::ErrorGuaranteed>, rustc_driver[f25ea7069dadae60]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  65:     0xffff7a168b58 - std[43bd97b51c4b7ccc]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[a23df4f4dba783b7]::util::run_in_thread_pool_with_globals<rustc_interface[a23df4f4dba783b7]::interface::run_compiler<core[3d0f08c789d39c5d]::result::Result<(), rustc_errors[8c811b1d8d2fea79]::ErrorGuaranteed>, rustc_driver[f25ea7069dadae60]::run_compiler::{closure#1}>::{closure#0}, core[3d0f08c789d39c5d]::result::Result<(), rustc_errors[8c811b1d8d2fea79]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3d0f08c789d39c5d]::result::Result<(), rustc_errors[8c811b1d8d2fea79]::ErrorGuaranteed>>
  66:     0xffff7a149930 - <<std[43bd97b51c4b7ccc]::thread::Builder>::spawn_unchecked_<rustc_interface[a23df4f4dba783b7]::util::run_in_thread_pool_with_globals<rustc_interface[a23df4f4dba783b7]::interface::run_compiler<core[3d0f08c789d39c5d]::result::Result<(), rustc_errors[8c811b1d8d2fea79]::ErrorGuaranteed>, rustc_driver[f25ea7069dadae60]::run_compiler::{closure#1}>::{closure#0}, core[3d0f08c789d39c5d]::result::Result<(), rustc_errors[8c811b1d8d2fea79]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3d0f08c789d39c5d]::result::Result<(), rustc_errors[8c811b1d8d2fea79]::ErrorGuaranteed>>::{closure#1} as core[3d0f08c789d39c5d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  67:     0xffff794a2234 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h58accc842c8ef0c5
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/boxed.rs:1988:9
  68:     0xffff794a2234 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h9aa66d4569106562
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/boxed.rs:1988:9
  69:     0xffff794a2234 - std::sys::unix::thread::Thread::new::thread_start::h7845f197aceb6559
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys/unix/thread.rs:108:17
  70:     0xffff792bd5c8 - start_thread
                               at ./nptl/./nptl/pthread_create.c:442:8
  71:     0xffff79325d1c - thread_start
                               at ./misc/../sysdeps/unix/sysv/linux/aarch64/clone.S:79
  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.68.2 (9eb3afe9e 2023-03-27) running on aarch64-unknown-linux-gnu

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: aborting due to previous error

Curiously, if I write:

let result: usize = names.iter().enumerate().map(|(i, name)| score((i, name))).sum();

the compiler is fine with it.

This is because the comiler is allowed to coerce &&str to &str for name, but can't do this with the function.

@aDotInTheVoid aDotInTheVoid added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Apr 17, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 17, 2023
@aDotInTheVoid
Copy link
Member

Interestingly, this fixed in nightly and beta

gh-aDotInTheVoid@dev-desktop-eu-1:~/tmp/ice-110447$ cargo +beta b
   Compiling ice-110447 v0.1.0 (/home/gh-aDotInTheVoid/tmp/ice-110447)
error[E0631]: type mismatch in function arguments
 --> src/main.rs:7:47
  |
1 | fn score(_: (usize, &str)) -> usize {
  | ----------------------------------- found signature defined here
...
7 |     let result = names.iter().enumerate().map(score);
  |                                           --- ^^^^^ expected due to this
  |                                           |
  |                                           required by a bound introduced by this call
  |
  = note: expected function signature `fn((_, &&str)) -> _`
             found function signature `for<'a> fn((_, &'a str)) -> _`
note: required by a bound in `map`
 --> /rustc/f18236dcd3d8191c91aca0c4ef43e1e27b6bc0dc/library/core/src/iter/traits/iterator.rs:796:5

For more information about this error, try `rustc --explain E0631`.
error: could not compile `ice-110447` due to previous error
gh-aDotInTheVoid@dev-desktop-eu-1:~/tmp/ice-110447$ cargo +nightly b
   Compiling ice-110447 v0.1.0 (/home/gh-aDotInTheVoid/tmp/ice-110447)
error[E0631]: type mismatch in function arguments
 --> src/main.rs:7:47
  |
1 | fn score(_: (usize, &str)) -> usize {
  | ----------------------------------- found signature defined here
...
7 |     let result = names.iter().enumerate().map(score);
  |                                           --- ^^^^^ expected due to this
  |                                           |
  |                                           required by a bound introduced by this call
  |
  = note: expected function signature `fn((_, &&str)) -> _`
             found function signature `for<'a> fn((_, &'a str)) -> _`
note: required by a bound in `map`
 --> /rustc/5cdb7886a5ece816864fab177f0c266ad4dd5358/library/core/src/iter/traits/iterator.rs:801:5

For more information about this error, try `rustc --explain E0631`.
error: could not compile `ice-110447` (bin "ice-110447") due to previous error

Given that beta gets promoted in 3 days, suspect it's not worth backpacking, but that's not my call to make

@nbdd0121
Copy link
Contributor

Looks like a duplicate of #109361

@jyn514 jyn514 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 17, 2023
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 19, 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) ❄️ regression-from-stable-to-stable Performance or correctness regression from one stable version to another. 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

6 participants