Skip to content
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

ICE: panic on function pointer argument coercion/typecheck #134005

Closed
RensHijdra opened this issue Dec 7, 2024 · 1 comment · Fixed by #134506
Closed

ICE: panic on function pointer argument coercion/typecheck #134005

RensHijdra opened this issue Dec 7, 2024 · 1 comment · Fixed by #134506
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RensHijdra
Copy link

Code

fn main() {
    // Panic
    let _ = [std::ops::Add::add, std::ops::Mul::mul, operator as fn(_, &_) -> _];
    let _ = [std::ops::Add::add, std::ops::Mul::mul, operator as fn(i64, &i64) -> i64];


    // Fine
    let _ = [std::ops::Add::add, std::ops::Mul::mul, operator as fn(_, _) -> _];
    let _ = [std::ops::Add::add, std::ops::Mul::mul];

    // Error [E0308]
    let _ = [std::ops::Add::add, operator as fn(i64, &i64) -> i64];
    let _ = [std::ops::Mul::mul, operator as fn(_, &_) -> _];

}
fn operator(x: i64, y: &i64) -> i64 {
    0
}

Meta

rustc --version --verbose:

rustc 1.85.0-nightly (8dc83770f 2024-12-06)
binary: rustc
commit-hash: 8dc83770f748c6cd16b342889ca2240397c19534
commit-date: 2024-12-06
host: x86_64-pc-windows-msvc
release: 1.85.0-nightly
LLVM version: 19.1.5

Error output

   Compiling bug v0.1.0 (C:\Users\rhijd\projects\bug)
thread 'rustc' panicked at compiler\rustc_hir_typeck\src\coercion.rs:1351:22:                                                                                                                                                     
called `Result::unwrap_err()` on an `Ok` value: InferOk { value: Binder { value: fn(?9t, ?10t) -> ?11t, bound_vars: [] }, obligations: [] }
stack backtrace:
   0:     0x7ffe40b46f91 - std::backtrace_rs::backtrace::dbghelp64::trace                                                                                                                                                         
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
   1:     0x7ffe40b46f91 - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ffe40b46f91 - std::sys::backtrace::_print_fmt                                                                                                                                                                        
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\sys\backtrace.rs:66
   3:     0x7ffe40b46f91 - std::sys::backtrace::impl$0::print::impl$0::fmt
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\sys\backtrace.rs:39
   4:     0x7ffe40b7914a - core::fmt::rt::Argument::fmt
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\core\src\fmt\rt.rs:177
   5:     0x7ffe40b7914a - core::fmt::write
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\core\src\fmt\mod.rs:1185
   6:     0x7ffe40b3d127 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\io\mod.rs:1887
   7:     0x7ffe40b46dd5 - std::sys::backtrace::BacktraceLock::print
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\sys\backtrace.rs:42
   8:     0x7ffe40b49cf3 - std::panicking::default_hook::closure$1
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\panicking.rs:284
   9:     0x7ffe40b49ad2 - std::panicking::default_hook
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\panicking.rs:311
  10:     0x7ffe4212fefa - core[b80e938d53cf19c0]::slice::sort::unstable::heapsort::heapsort::<((rustc_lint_defs[4d15e40553160eeb]::Level, &str), usize), <((rustc_lint_defs[4d15e40553160eeb]::Level, &str), usize) as core[b80e938d53cf19c0]::cmp::PartialOrd>::lt>
  11:     0x7ffe40b4a522 - alloc::boxed::impl$30::call
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\alloc\src\boxed.rs:1984
  12:     0x7ffe40b4a522 - std::panicking::rust_panic_with_hook
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\panicking.rs:825
  13:     0x7ffe40b4a279 - std::panicking::begin_panic_handler::closure$0
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\panicking.rs:690
  14:     0x7ffe40b47a5f - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\sys\backtrace.rs:168
  15:     0x7ffe40b49e7e - std::panicking::begin_panic_handler
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\panicking.rs:681
  16:     0x7ffe439c9a71 - core::panicking::panic_fmt
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\core\src\panicking.rs:75
  17:     0x7ffe439c9fb0 - core::result::unwrap_failed
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\core\src\result.rs:1699
  18:     0x7ffe40cf09b8 - <alloc[1333525787bd5639]::raw_vec::RawVec<rustc_hir_typeck[a44d2be023218208]::method::probe::Candidate>>::grow_one                                                                                     
  19:     0x7ffe40d459a7 - <alloc[1333525787bd5639]::raw_vec::RawVec<rustc_hir_typeck[a44d2be023218208]::method::probe::Candidate>>::grow_one
  20:     0x7ffe40d4797c - <alloc[1333525787bd5639]::raw_vec::RawVec<rustc_hir_typeck[a44d2be023218208]::method::probe::Candidate>>::grow_one
  21:     0x7ffe40ce10ed - <alloc[1333525787bd5639]::raw_vec::RawVec<rustc_hir_typeck[a44d2be023218208]::method::probe::Candidate>>::grow_one
  22:     0x7ffe40daa374 - rustc_hir_typeck[a44d2be023218208]::typeck
  23:     0x7ffe40d99ad7 - rustc_hir_typeck[a44d2be023218208]::typeck
  24:     0x7ffe418c675b - rustc_query_impl[8fd2fa4db52211cd]::plumbing::query_key_hash_verify_all
  25:     0x7ffe41811aab - RINvNtNtCs5WnBY9SOFw2_18rustc_query_system5query8plumbing17try_execute_queryINtCsclzuBKs5ZvZ_16rustc_query_impl13DynamicConfigINtNtCsc8IDRpIi7e_21rustc_data_structures9vec_cache8VecCacheNtNtCsfxawg7UaaO9_10rustc_span6def_id10LocalDefIdINtNtNtCs2Ms1sryjPDY_
  26:     0x7ffe418cee74 - rustc_query_impl[8fd2fa4db52211cd]::plumbing::query_key_hash_verify_all
  27:     0x7ffe40e114f4 - <hashbrown[44c28b674df2b54]::raw::RawTable<(&usize, ())>>::reserve_rehash::<hashbrown[44c28b674df2b54]::map::make_hasher<&usize, (), rustc_hash[1ae4ed8f5a935617]::FxBuildHasher>::{closure#0}>
  28:     0x7ffe40e92018 - rustc_hir_analysis[27d4dc76592869da]::check_crate
  29:     0x7ffe40bbb585 - rustc_interface[85abe4d21adbac22]::passes::resolver_for_lowering_raw
  30:     0x7ffe3db915be - rustc_interface[85abe4d21adbac22]::passes::analysis
  31:     0x7ffe407432cb - <alloc[1333525787bd5639]::sync::Arc<alloc[1333525787bd5639]::vec::Vec<rustc_middle[2065cd2648f02524]::ty::region::Region>>>::drop_slow
  32:     0x7ffe4064c90d - RINvNtNtCs5WnBY9SOFw2_18rustc_query_system5query8plumbing17try_execute_queryINtCsclzuBKs5ZvZ_16rustc_query_impl13DynamicConfigINtNtB4_6caches11SingleCacheINtNtNtCs2Ms1sryjPDY_12rustc_middle5query5erase6ErasedAhj1_EEKb0_KB3s_KB3s_ENtNtB1f_8plumbing9QueryCtx
  33:     0x7ffe40748e63 - rustc_query_impl[8fd2fa4db52211cd]::query_system
  34:     0x7ffe3db53374 - RINvNtNtCs2DHW9XDaqP7_3std3sys9backtrace28___rust_begin_short_backtraceNCNCNCINvMNtB6_6threadNtB1h_7Builder16spawn_unchecked_INtNtCs1EcCWnECj43_5alloc5boxed3BoxDINtNtNtCsfNJj4hWmu86_4core3ops8function6FnOnceuEp6OutputuNtNtB2G_6marker4SendEL_EuEs_000uECs9eQ
  35:     0x7ffe3db50749 - RINvNtNtCs2DHW9XDaqP7_3std3sys9backtrace28___rust_begin_short_backtraceNCNCINvNtCsbtwRuUusrE4_15rustc_interface4util26run_in_thread_with_globalsNCINvB1e_31run_in_thread_pool_with_globalsNCINvNtB1g_9interface12run_compilerINtNtCsfNJj4hWmu86_4core6result6Res
  36:     0x7ffe3db57a65 - RINvNtNtCs2DHW9XDaqP7_3std3sys9backtrace28___rust_begin_short_backtraceNCNCNCINvMNtB6_6threadNtB1h_7Builder16spawn_unchecked_INtNtCs1EcCWnECj43_5alloc5boxed3BoxDINtNtNtCsfNJj4hWmu86_4core3ops8function6FnOnceuEp6OutputuNtNtB2G_6marker4SendEL_EuEs_000uECs9eQ
  37:     0x7ffe40b5c1dd - alloc::boxed::impl$28::call_once
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\alloc\src\boxed.rs:1970
  38:     0x7ffe40b5c1dd - alloc::boxed::impl$28::call_once
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\alloc\src\boxed.rs:1970
  39:     0x7ffe40b5c1dd - std::sys::pal::windows::thread::impl$0::new::thread_start
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\sys\pal\windows\thread.rs:55
  40:     0x7fff645b259d - BaseThreadInitThunk
  41:     0x7fff65acaf38 - RtlUserThreadStart

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: please make sure that you have updated to the latest nightly

note: please attach the file at `C:\Users\rhijd\projects\bug\rustc-ice-2024-12-07T11_27_51-15660.txt` to your bug report

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 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `bug` (bin "bug")                                                                                                                                                                                        

Caused by:
  process didn't exit successfully: `C:\Users\rhijd\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\bin\rustc.exe --crate-name bug --edition=2021 'src\main.rs' --error-format=json --json=diagnostic-rendered-ansi,artifacts,fut
ure-incompat --diagnostic-width=226 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=7d0ebf5a1f591c4e --out-dir 'C:\Users\rhijd\projects\bug\target\debug\deps' -C 'incremental=C:\Users\rhijd\projects\bug\target\debug\incremental' -L 'dependency=C:\Users\rhijd\projects\bug\target\debug\deps'` (exit code: 101)
Backtrace

thread 'rustc' panicked at compiler\rustc_hir_typeck\src\coercion.rs:1351:22:
called `Result::unwrap_err()` on an `Ok` value: InferOk { value: Binder { value: fn(?9t, ?10t) -> ?11t, bound_vars: [] }, obligations: [] }
stack backtrace:
   0:     0x7ffe40b2f4b3 - std::backtrace_rs::backtrace::dbghelp64::trace
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
   1:     0x7ffe40b2f4b3 - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ffe40b2f4b3 - std::backtrace::Backtrace::create
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\backtrace.rs:331
   3:     0x7ffe40b2f3fa - std::backtrace::Backtrace::force_capture
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\backtrace.rs:312
   4:     0x7ffe42130771 - core[b80e938d53cf19c0]::slice::sort::unstable::heapsort::heapsort::<((rustc_lint_defs[4d15e40553160eeb]::Level, &str), usize), <((rustc_lint_defs[4d15e40553160eeb]::Level, &str), usize) as core[b80e938d53cf19c0]::cmp::PartialOrd>::lt>
   5:     0x7ffe40b4a522 - alloc::boxed::impl$30::call
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\alloc\src\boxed.rs:1984
   6:     0x7ffe40b4a522 - std::panicking::rust_panic_with_hook
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\panicking.rs:825
   7:     0x7ffe40b4a279 - std::panicking::begin_panic_handler::closure$0
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\panicking.rs:690
   8:     0x7ffe40b47a5f - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\sys\backtrace.rs:168
   9:     0x7ffe40b49e7e - std::panicking::begin_panic_handler
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\panicking.rs:681
  10:     0x7ffe439c9a71 - core::panicking::panic_fmt
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\core\src\panicking.rs:75
  11:     0x7ffe439c9fb0 - core::result::unwrap_failed
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\core\src\result.rs:1699
  12:     0x7ffe40cf09b8 - <alloc[1333525787bd5639]::raw_vec::RawVec<rustc_hir_typeck[a44d2be023218208]::method::probe::Candidate>>::grow_one
  13:     0x7ffe40d459a7 - <alloc[1333525787bd5639]::raw_vec::RawVec<rustc_hir_typeck[a44d2be023218208]::method::probe::Candidate>>::grow_one
  14:     0x7ffe40d4797c - <alloc[1333525787bd5639]::raw_vec::RawVec<rustc_hir_typeck[a44d2be023218208]::method::probe::Candidate>>::grow_one
  15:     0x7ffe40ce10ed - <alloc[1333525787bd5639]::raw_vec::RawVec<rustc_hir_typeck[a44d2be023218208]::method::probe::Candidate>>::grow_one
  16:     0x7ffe40daa374 - rustc_hir_typeck[a44d2be023218208]::typeck
  17:     0x7ffe40d99ad7 - rustc_hir_typeck[a44d2be023218208]::typeck
  18:     0x7ffe418c675b - rustc_query_impl[8fd2fa4db52211cd]::plumbing::query_key_hash_verify_all
  19:     0x7ffe41811aab - RINvNtNtCs5WnBY9SOFw2_18rustc_query_system5query8plumbing17try_execute_queryINtCsclzuBKs5ZvZ_16rustc_query_impl13DynamicConfigINtNtCsc8IDRpIi7e_21rustc_data_structures9vec_cache8VecCacheNtNtCsfxawg7UaaO9_10rustc_span6def_id10LocalDefIdINtNtNtCs2Ms1sryjPDY_
  20:     0x7ffe418cee74 - rustc_query_impl[8fd2fa4db52211cd]::plumbing::query_key_hash_verify_all
  21:     0x7ffe40e114f4 - <hashbrown[44c28b674df2b54]::raw::RawTable<(&usize, ())>>::reserve_rehash::<hashbrown[44c28b674df2b54]::map::make_hasher<&usize, (), rustc_hash[1ae4ed8f5a935617]::FxBuildHasher>::{closure#0}>
  22:     0x7ffe40e92018 - rustc_hir_analysis[27d4dc76592869da]::check_crate
  23:     0x7ffe40bbb585 - rustc_interface[85abe4d21adbac22]::passes::resolver_for_lowering_raw
  24:     0x7ffe3db915be - rustc_interface[85abe4d21adbac22]::passes::analysis
  25:     0x7ffe407432cb - <alloc[1333525787bd5639]::sync::Arc<alloc[1333525787bd5639]::vec::Vec<rustc_middle[2065cd2648f02524]::ty::region::Region>>>::drop_slow
  26:     0x7ffe4064c90d - RINvNtNtCs5WnBY9SOFw2_18rustc_query_system5query8plumbing17try_execute_queryINtCsclzuBKs5ZvZ_16rustc_query_impl13DynamicConfigINtNtB4_6caches11SingleCacheINtNtNtCs2Ms1sryjPDY_12rustc_middle5query5erase6ErasedAhj1_EEKb0_KB3s_KB3s_ENtNtB1f_8plumbing9QueryCtx
  27:     0x7ffe40748e63 - rustc_query_impl[8fd2fa4db52211cd]::query_system
  28:     0x7ffe3db53374 - RINvNtNtCs2DHW9XDaqP7_3std3sys9backtrace28___rust_begin_short_backtraceNCNCNCINvMNtB6_6threadNtB1h_7Builder16spawn_unchecked_INtNtCs1EcCWnECj43_5alloc5boxed3BoxDINtNtNtCsfNJj4hWmu86_4core3ops8function6FnOnceuEp6OutputuNtNtB2G_6marker4SendEL_EuEs_000uECs9eQ
  29:     0x7ffe3db50749 - RINvNtNtCs2DHW9XDaqP7_3std3sys9backtrace28___rust_begin_short_backtraceNCNCINvNtCsbtwRuUusrE4_15rustc_interface4util26run_in_thread_with_globalsNCINvB1e_31run_in_thread_pool_with_globalsNCINvNtB1g_9interface12run_compilerINtNtCsfNJj4hWmu86_4core6result6Res
  30:     0x7ffe3db57a65 - RINvNtNtCs2DHW9XDaqP7_3std3sys9backtrace28___rust_begin_short_backtraceNCNCNCINvMNtB6_6threadNtB1h_7Builder16spawn_unchecked_INtNtCs1EcCWnECj43_5alloc5boxed3BoxDINtNtNtCsfNJj4hWmu86_4core3ops8function6FnOnceuEp6OutputuNtNtB2G_6marker4SendEL_EuEs_000uECs9eQ
  31:     0x7ffe40b5c1dd - alloc::boxed::impl$28::call_once
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\alloc\src\boxed.rs:1970
  32:     0x7ffe40b5c1dd - alloc::boxed::impl$28::call_once
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\alloc\src\boxed.rs:1970
  33:     0x7ffe40b5c1dd - std::sys::pal::windows::thread::impl$0::new::thread_start
                               at /rustc/8dc83770f748c6cd16b342889ca2240397c19534/library\std\src\sys\pal\windows\thread.rs:55
  34:     0x7fff645b259d - BaseThreadInitThunk
  35:     0x7fff65acaf38 - RtlUserThreadStart


rustc version: 1.85.0-nightly (8dc83770f 2024-12-06)
platform: x86_64-pc-windows-msvc

query stack during panic:
#0 [typeck] type-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack

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

bisects to #126673 cc @oli-obk

smaller:

fn main() {
    let _ = [std::ops::Add::add, std::ops::Mul::mul, main as fn(_, &_)];
}

@oli-obk oli-obk self-assigned this Dec 7, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 7, 2024
@matthiaskrgr matthiaskrgr added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-bisection Status: a bisection has been found for this issue labels Dec 14, 2024
@bors bors closed this as completed in 4f053b1 Dec 20, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 20, 2024
Rollup merge of rust-lang#134506 - oli-obk:push-mrrulszyuslt, r=jieyouxu

Remove a duplicated check that doesn't do anything anymore.

fixes rust-lang#134005

This code didn't actually `lub` the type of the previous expressions, but just the current type over and over again. Changing it to using the actual expression type does not change anything either, so may as well remove the entire loop.
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) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants