Skip to content

Index out-of-bounds in rustc when running "cargo llvm-cov" on function that returns impl AsyncFnMut() #135293

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
qbradley opened this issue Jan 9, 2025 · 7 comments
Assignees
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

@qbradley
Copy link

qbradley commented Jan 9, 2025

Minimal example below.

Code compiles with cargo build but rustc crashes when running cargo llvm-cov.

RUSTC_BOOSTRAP="1" is set so that feature(async_closure) can be used with 1.83 stable compiler.

Code

#![feature(async_closure)]
use std::ops::AsyncFnMut;
fn fn_once_to_fn_mut() -> impl AsyncFnMut()
{
    async || ()
}

Meta

rustc --version --verbose:

rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-unknown-linux-gnu
release: 1.83.0
LLVM version: 19.1.1

Error output

info: cargo-llvm-cov currently setting cfg(coverage); you can opt-out it by passing --no-cfg-coverage
   Compiling repro v0.1.0 (/home/azureuser/src/repro)
warning: function `fn_once_to_fn_mut` is never used
 --> src/main.rs:3:4
  |
3 | fn fn_once_to_fn_mut() -> impl AsyncFnMut()
  |    ^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

thread 'rustc' panicked at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/compiler/rustc_middle/src/hir/mod.rs:179:84:
index out of bounds: the len is 11 but the index is 11
stack backtrace:
   0:     0x7fa066d6512a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h5b6bd5631a6d1f6b
   1:     0x7fa0675468f8 - core::fmt::write::h7550c97b06c86515
   2:     0x7fa06877db91 - std::io::Write::write_fmt::h7b09c64fe0be9c84
   3:     0x7fa066d64f82 - std::sys::backtrace::BacktraceLock::print::h2395ccd2c84ba3aa
   4:     0x7fa066d67456 - std::panicking::default_hook::{{closure}}::he19d4c7230e07961
   5:     0x7fa066d672a0 - std::panicking::default_hook::hf614597d3c67bbdb
   6:     0x7fa065e29556 - std[c6eb78587944e35c]::panicking::update_hook::<alloc[148a978a4a62f5d]::boxed::Box<rustc_driver_impl[4c2d2ad79fb810ac]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x7fa066d67b68 - std::panicking::rust_panic_with_hook::h8942133a8b252070
   8:     0x7fa066d6793a - std::panicking::begin_panic_handler::{{closure}}::hb5f5963570096b29
   9:     0x7fa066d655d9 - std::sys::backtrace::__rust_end_short_backtrace::h6208cedc1922feda
  10:     0x7fa066d675fc - rust_begin_unwind
  11:     0x7fa0647e0160 - core::panicking::panic_fmt::h0c3082644d1bf418
  12:     0x7fa0654cdb6a - core::panicking::panic_bounds_check::h8307ccead484a122
  13:     0x7fa067819646 - rustc_query_impl[db795c774d495014]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db795c774d495014]::query_impl::local_def_id_to_hir_id::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 8usize]>>
  14:     0x7fa06781b183 - rustc_query_system[b2bb6e43dd6b7fda]::query::plumbing::try_execute_query::<rustc_query_impl[db795c774d495014]::DynamicConfig<rustc_query_system[b2bb6e43dd6b7fda]::query::caches::VecCache<rustc_span[3e5cf3424d44936d]::def_id::LocalDefId, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[db795c774d495014]::plumbing::QueryCtxt, true>
  15:     0x7fa067819bcc - rustc_query_impl[db795c774d495014]::query_impl::local_def_id_to_hir_id::get_query_incr::__rust_end_short_backtrace
  16:     0x7fa06659282a - <rustc_middle[a886f61dbc61428a]::ty::context::TyCtxt>::get_attrs::<rustc_span[3e5cf3424d44936d]::def_id::LocalDefId>
  17:     0x7fa066638dc3 - rustc_mir_transform[b36c87ceb4bb9a8e]::coverage::query::coverage_attr_on
  18:     0x7fa06686f5c7 - rustc_query_impl[db795c774d495014]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db795c774d495014]::query_impl::coverage_attr_on::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 1usize]>>
  19:     0x7fa06797019c - rustc_query_system[b2bb6e43dd6b7fda]::query::plumbing::try_execute_query::<rustc_query_impl[db795c774d495014]::DynamicConfig<rustc_query_system[b2bb6e43dd6b7fda]::query::caches::VecCache<rustc_span[3e5cf3424d44936d]::def_id::LocalDefId, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[db795c774d495014]::plumbing::QueryCtxt, true>
  20:     0x7fa066878950 - rustc_query_impl[db795c774d495014]::query_impl::coverage_attr_on::get_query_incr::__rust_end_short_backtrace
  21:     0x7fa066638ccb - rustc_mir_transform[b36c87ceb4bb9a8e]::coverage::query::is_eligible_for_coverage
  22:     0x7fa06663ef0e - <rustc_mir_transform[b36c87ceb4bb9a8e]::coverage::InstrumentCoverage as rustc_mir_transform[b36c87ceb4bb9a8e]::pass_manager::MirPass>::run_pass
  23:     0x7fa064b15ff9 - rustc_mir_transform[b36c87ceb4bb9a8e]::mir_promoted
  24:     0x7fa067aef4a0 - rustc_query_impl[db795c774d495014]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db795c774d495014]::query_impl::mir_promoted::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 16usize]>>
  25:     0x7fa067af45aa - rustc_query_system[b2bb6e43dd6b7fda]::query::plumbing::try_execute_query::<rustc_query_impl[db795c774d495014]::DynamicConfig<rustc_query_system[b2bb6e43dd6b7fda]::query::caches::VecCache<rustc_span[3e5cf3424d44936d]::def_id::LocalDefId, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[db795c774d495014]::plumbing::QueryCtxt, true>
  26:     0x7fa067af3d14 - rustc_query_impl[db795c774d495014]::query_impl::mir_promoted::get_query_incr::__rust_end_short_backtrace
  27:     0x7fa0665ab714 - rustc_middle[a886f61dbc61428a]::query::plumbing::query_get_at::<rustc_query_system[b2bb6e43dd6b7fda]::query::caches::VecCache<rustc_span[3e5cf3424d44936d]::def_id::LocalDefId, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 16usize]>>>
  28:     0x7fa06668e53a - rustc_mir_transform[b36c87ceb4bb9a8e]::coroutine::mir_coroutine_witnesses
  29:     0x7fa06686fa64 - rustc_query_impl[db795c774d495014]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db795c774d495014]::query_impl::mir_coroutine_witnesses::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 8usize]>>
  30:     0x7fa06797949a - rustc_query_system[b2bb6e43dd6b7fda]::query::plumbing::try_execute_query::<rustc_query_impl[db795c774d495014]::DynamicConfig<rustc_query_system[b2bb6e43dd6b7fda]::query::caches::DefIdCache<rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[db795c774d495014]::plumbing::QueryCtxt, true>
  31:     0x7fa066877ea1 - rustc_query_impl[db795c774d495014]::query_impl::mir_coroutine_witnesses::get_query_incr::__rust_end_short_backtrace
  32:     0x7fa06771ba23 - rustc_mir_transform[b36c87ceb4bb9a8e]::mir_drops_elaborated_and_const_checked
  33:     0x7fa06771acfd - rustc_query_impl[db795c774d495014]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db795c774d495014]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 8usize]>>
  34:     0x7fa06781b305 - rustc_query_system[b2bb6e43dd6b7fda]::query::plumbing::try_execute_query::<rustc_query_impl[db795c774d495014]::DynamicConfig<rustc_query_system[b2bb6e43dd6b7fda]::query::caches::VecCache<rustc_span[3e5cf3424d44936d]::def_id::LocalDefId, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[db795c774d495014]::plumbing::QueryCtxt, true>
  35:     0x7fa067e173f2 - rustc_query_impl[db795c774d495014]::query_impl::mir_drops_elaborated_and_const_checked::get_query_incr::__rust_end_short_backtrace
  36:     0x7fa067a2ff19 - rustc_mir_transform[b36c87ceb4bb9a8e]::optimized_mir
  37:     0x7fa067a2d369 - rustc_query_impl[db795c774d495014]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db795c774d495014]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 8usize]>>
  38:     0x7fa06797949a - rustc_query_system[b2bb6e43dd6b7fda]::query::plumbing::try_execute_query::<rustc_query_impl[db795c774d495014]::DynamicConfig<rustc_query_system[b2bb6e43dd6b7fda]::query::caches::DefIdCache<rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[db795c774d495014]::plumbing::QueryCtxt, true>
  39:     0x7fa067977aa3 - rustc_query_impl[db795c774d495014]::query_impl::optimized_mir::get_query_incr::__rust_end_short_backtrace
  40:     0x7fa065c9d127 - rustc_codegen_llvm[e2813e29308ec38d]::coverageinfo::mapgen::finalize
  41:     0x7fa0682c70e1 - rustc_codegen_llvm[e2813e29308ec38d]::base::compile_codegen_unit::module_codegen
  42:     0x7fa068359140 - <rustc_codegen_llvm[e2813e29308ec38d]::LlvmCodegenBackend as rustc_codegen_ssa[76f2c5b87770fd75]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  43:     0x7fa068356c82 - <rustc_codegen_llvm[e2813e29308ec38d]::LlvmCodegenBackend as rustc_codegen_ssa[76f2c5b87770fd75]::traits::backend::CodegenBackend>::codegen_crate
  44:     0x7fa0685e1ab9 - <rustc_interface[88a02114bbdb2383]::queries::Linker>::codegen_and_build_linker
  45:     0x7fa0682871d4 - rustc_interface[88a02114bbdb2383]::interface::run_compiler::<core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>, rustc_driver_impl[4c2d2ad79fb810ac]::run_compiler::{closure#0}>::{closure#1}
  46:     0x7fa0682783d9 - std[c6eb78587944e35c]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[88a02114bbdb2383]::util::run_in_thread_with_globals<rustc_interface[88a02114bbdb2383]::interface::run_compiler<core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>, rustc_driver_impl[4c2d2ad79fb810ac]::run_compiler::{closure#0}>::{closure#1}, core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>>
  47:     0x7fa068347fac - <<std[c6eb78587944e35c]::thread::Builder>::spawn_unchecked_<rustc_interface[88a02114bbdb2383]::util::run_in_thread_with_globals<rustc_interface[88a02114bbdb2383]::interface::run_compiler<core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>, rustc_driver_impl[4c2d2ad79fb810ac]::run_compiler::{closure#0}>::{closure#1}, core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>>::{closure#1} as core[c06ff78fa456ca03]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  48:     0x7fa068348a6b - std::sys::pal::unix::thread::Thread::new::thread_start::hcc78f3943333fa94
  49:     0x7fa0628f0609 - start_thread
                               at /build/glibc-LcI20x/glibc-2.31/nptl/pthread_create.c:477:8
  50:     0x7fa062815353 - clone
                               at /build/glibc-LcI20x/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  51:                0x0 - <unknown>

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 `/home/azureuser/src/repro/rustc-ice-2025-01-09T17_25_34-13041.txt` to your bug report

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] -C instrument-coverage

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

query stack during panic:
#0 [local_def_id_to_hir_id] getting HIR ID of `fn_once_to_fn_mut::{closure#0}::{closure#1}`
#1 [coverage_attr_on] checking for `#[coverage(..)]` on `fn_once_to_fn_mut::{closure#0}::{closure#1}`
end of query stack
warning: `repro` (bin "repro" test) generated 1 warning
error: could not compile `repro` (bin "repro" test); 1 warning emitted

Caused by:
  process didn't exit successfully: `/home/azureuser/.rustup/toolchains/1.83-x86_64-unknown-linux-gnu/bin/rustc --crate-name repro --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=132 --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --test --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=a113d72d1915d3ae -C extra-filename=-a113d72d1915d3ae --out-dir /home/azureuser/src/repro/target/llvm-cov-target/debug/deps -C incremental=/home/azureuser/src/repro/target/llvm-cov-target/debug/incremental -L dependency=/home/azureuser/src/repro/target/llvm-cov-target/debug/deps -C instrument-coverage --cfg=coverage --cfg=trybuild_no_target` (exit status: 101)
error: process didn't exit successfully: `/home/azureuser/.rustup/toolchains/1.83-x86_64-unknown-linux-gnu/bin/cargo test --tests --manifest-path /home/azureuser/src/repro/Cargo.toml --target-dir /home/azureuser/src/repro/target/llvm-cov-target` (exit status: 101)
Backtrace

thread 'rustc' panicked at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/compiler/rustc_middle/src/hir/mod.rs:179:84:
index out of bounds: the len is 12 but the index is 12
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_bounds_check
      [... omitted 1 frame ...]
   3: <rustc_middle::ty::context::TyCtxt>::get_attrs::<rustc_span::def_id::LocalDefId>
   4: rustc_mir_transform::coverage::query::coverage_attr_on
      [... omitted 1 frame ...]
   5: rustc_mir_transform::coverage::query::is_eligible_for_coverage
   6: <rustc_mir_transform::coverage::InstrumentCoverage as rustc_mir_transform::pass_manager::MirPass>::run_pass
   7: rustc_mir_transform::mir_promoted
      [... omitted 1 frame ...]
   8: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 16]>>>
   9: rustc_mir_transform::coroutine::mir_coroutine_witnesses
      [... omitted 1 frame ...]
  10: rustc_mir_transform::mir_drops_elaborated_and_const_checked
      [... omitted 1 frame ...]
  11: rustc_mir_transform::optimized_mir
      [... omitted 1 frame ...]
  12: rustc_codegen_llvm::coverageinfo::mapgen::finalize
  13: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  14: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  15: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  16: <rustc_interface::queries::Linker>::codegen_and_build_linker
  17: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@qbradley qbradley 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 Jan 9, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 9, 2025
@jieyouxu
Copy link
Member

jieyouxu commented Jan 9, 2025

Does this repro on a variant without RUSTC_BOOTSTRAP on latest stable 1.84.0? Users are not supposed to use RUSTC_BOOTSTRAP at all.

@compiler-errors compiler-errors self-assigned this Jan 9, 2025
@compiler-errors
Copy link
Member

compiler-errors commented Jan 9, 2025

If this doesn't reproduce on nightly rustc, then there's nothing we can do here :) So yes, please check that.

@jieyouxu
Copy link
Member

jieyouxu commented Jan 9, 2025

I tried this locally, on latest nightly, and it does not ICE:

rustc 1.86.0-nightly (a580b5c37 2025-01-08)
binary: rustc
commit-hash: a580b5c379b4fca50dfe5afc0fc0ce00921e4e00
commit-date: 2025-01-08
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.6
[01:36] Joe:foo | RUSTC_ICE=0 rustc +nightly test.rs --crate-type="lib" > /dev/null
error[E0425]: cannot find value `async` in this scope
 --> test.rs:5:5
  |
5 |     async || ()
  |     ^^^^^ not found in this scope

warning: the feature `async_closure` has been stable since 1.86.0-nightly and no longer requires an attribute to enable
 --> test.rs:1:12
  |
1 | #![feature(async_closure)]
  |            ^^^^^^^^^^^^^
  |
  = note: `#[warn(stable_features)]` on by default

error[E0308]: mismatched types
 --> test.rs:5:14
  |
5 |     async || ()
  |              ^^ expected `bool`, found `()`

error[E0277]: the trait bound `bool: AsyncFnMut()` is not satisfied
 --> test.rs:3:27
  |
3 | fn fn_once_to_fn_mut() -> impl AsyncFnMut()
  |                           ^^^^^^^^^^^^^^^^^ the trait `AsyncFnMut()` is not implemented for `bool`
4 | {
5 |     async || ()
  |     ----------- return type was inferred to be `bool` here

error: aborting due to 3 previous errors; 1 warning emitted

Some errors have detailed explanations: E0277, E0308, E0425.
For more information about an error, try `rustc --explain E0277`.

@qbradley
Copy link
Author

qbradley commented Jan 9, 2025

"cargo +nightly llvm-cov" does not repro for me

@taiki-e
Copy link
Member

taiki-e commented Jan 9, 2025

I guess this is #131190 (fixed in 1.84).

@jieyouxu
Copy link
Member

jieyouxu commented Jan 9, 2025

Then I think we can close this, thank you for the report.

@jieyouxu jieyouxu closed this as not planned Won't fix, can't repro, duplicate, stale Jan 9, 2025
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 9, 2025
@qbradley
Copy link
Author

qbradley commented Jan 9, 2025

I see 1.84 was just released today, great!

I can confirm that it is fixed in 1.84, thanks.

# for free to join this conversation on GitHub. Already have an account? # 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

5 participants