Skip to content

ICE: un_derefer: index out of bounds #139556

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

Open
matthiaskrgr opened this issue Apr 8, 2025 · 2 comments
Open

ICE: un_derefer: index out of bounds #139556

matthiaskrgr opened this issue Apr 8, 2025 · 2 comments
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` 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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Apr 8, 2025

auto-reduced (treereduce-rust):

trait T {}

type Alias<'a> = impl T;

struct S;
impl<'a> T for &'a S {}

#[define_opaque(Alias)]
fn with_positive(fun: impl Fn(Alias<'_>)) {
    with_positive(|&n| ());
}

original (tests/ui/type-alias-impl-trait/error-tainting-issue-122904.rs)

// We previously didn't taint the borrowck result in this test,
// causing an ICE later on.
#![feature(type_alias_impl_trait)]
trait T {}

type Alias<'a> = impl T;

struct S;
impl<'a> T for &'a S {}

#[define_opaque(Alias)]
fn with_positive(fun: impl Fn(Alias<'_>)) {
    //~^ WARN function cannot return without recursing
    with_positive(|&n| ());
    //~^ ERROR cannot move out of a shared reference
}

fn main() {}

Version information

rustc 1.88.0-nightly (d4f880f8c 2025-04-08)
binary: rustc
commit-hash: d4f880f8ce832cd7560bb2f1ebc34f967055ffd7
commit-date: 2025-04-08
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0658]: use of unstable library feature `type_alias_impl_trait`: `type_alias_impl_trait` has open design concerns
 --> /tmp/icemaker_global_tempdir.mDqISGx00Oyn/rustc_testrunner_tmpdir_reporting.kodIhQfhoesH/mvce.rs:8:3
  |
8 | #[define_opaque(Alias)]
  |   ^^^^^^^^^^^^^
  |
  = note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
  = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
  = note: this compiler was built on 2025-04-08; consider upgrading it if it is out of date

error[E0658]: `impl Trait` in type aliases is unstable
 --> /tmp/icemaker_global_tempdir.mDqISGx00Oyn/rustc_testrunner_tmpdir_reporting.kodIhQfhoesH/mvce.rs:3:18
  |
3 | type Alias<'a> = impl T;
  |                  ^^^^^^
  |
  = note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
  = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
  = note: this compiler was built on 2025-04-08; consider upgrading it if it is out of date

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.mDqISGx00Oyn/rustc_testrunner_tmpdir_reporting.kodIhQfhoesH/mvce.rs:11:2
   |
11 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.mDqISGx00Oyn/rustc_testrunner_tmpdir_reporting.kodIhQfhoesH/mvce.rs`

warning: unused variable: `fun`
 --> /tmp/icemaker_global_tempdir.mDqISGx00Oyn/rustc_testrunner_tmpdir_reporting.kodIhQfhoesH/mvce.rs:9:18
  |
9 | fn with_positive(fun: impl Fn(Alias<'_>)) {
  |                  ^^^ help: if this is intentional, prefix it with an underscore: `_fun`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: function cannot return without recursing
  --> /tmp/icemaker_global_tempdir.mDqISGx00Oyn/rustc_testrunner_tmpdir_reporting.kodIhQfhoesH/mvce.rs:9:1
   |
9  | fn with_positive(fun: impl Fn(Alias<'_>)) {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
10 |     with_positive(|&n| ());
   |     ---------------------- recursive call site
   |
   = help: a `loop` may express intention better if this is on purpose
   = note: `#[warn(unconditional_recursion)]` on by default

warning: unused variable: `n`
  --> /tmp/icemaker_global_tempdir.mDqISGx00Oyn/rustc_testrunner_tmpdir_reporting.kodIhQfhoesH/mvce.rs:10:21
   |
10 |     with_positive(|&n| ());
   |                     ^ help: if this is intentional, prefix it with an underscore: `_n`

error[E0507]: cannot move out of a shared reference
  --> /tmp/icemaker_global_tempdir.mDqISGx00Oyn/rustc_testrunner_tmpdir_reporting.kodIhQfhoesH/mvce.rs:10:20
   |
10 |     with_positive(|&n| ());
   |                    ^-
   |                     |
   |                     data moved here
   |                     move occurs because `n` has type `S`, which does not implement the `Copy` trait
   |
help: consider removing the borrow
   |
10 -     with_positive(|&n| ());
10 +     with_positive(|n| ());
   |


thread 'rustc' panicked at /rustc/d4f880f8ce832cd7560bb2f1ebc34f967055ffd7/compiler/rustc_mir_dataflow/src/un_derefer.rs:67:20:
index out of bounds: the len is 0 but the index is 0
stack backtrace:
   0:     0x7f2191499603 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h3f19261cd8690700
   1:     0x7f2191c060d1 - core::fmt::write::h21899ebf6733481f
   2:     0x7f2192d73851 - std::io::Write::write_fmt::h70e1e83b7747c27c
   3:     0x7f2191499462 - std::sys::backtrace::BacktraceLock::print::hf2e916f773277a1f
   4:     0x7f219149cf4a - std::panicking::default_hook::{{closure}}::h874106e9c340c371
   5:     0x7f219149cacf - std::panicking::default_hook::h404e192f8eb0363e
   6:     0x7f21904f45d3 - std[d6b00ef7faf64c8c]::panicking::update_hook::<alloc[3e49862987180319]::boxed::Box<rustc_driver_impl[a1c67d496eb7e262]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7f219149d7c3 - std::panicking::rust_panic_with_hook::h91f9f0cd297cb172
   8:     0x7f219149d4ba - std::panicking::begin_panic_handler::{{closure}}::h9f6a304f6e81ab68
   9:     0x7f2191499ac9 - std::sys::backtrace::__rust_end_short_backtrace::hd003b1223921a624
  10:     0x7f219149d17d - __rustc[8a6480b3f5e8ef7f]::rust_begin_unwind
  11:     0x7f218de960e0 - core::panicking::panic_fmt::h5aa30622f686c25e
  12:     0x7f218f21d7f0 - core::panicking::panic_bounds_check::hb55472f2614f1ea6
  13:     0x7f218e509b58 - <rustc_mir_dataflow[7f4ab855dc9b8628]::move_paths::builder::MoveDataBuilder<<rustc_mir_transform[2c11676f69282928]::elaborate_drops::ElaborateDrops as rustc_mir_transform[2c11676f69282928]::pass_manager::MirPass>::run_pass::{closure#0}>>::gather_move
  14:     0x7f218e4ee4f3 - <rustc_mir_transform[2c11676f69282928]::elaborate_drops::ElaborateDrops as rustc_mir_transform[2c11676f69282928]::pass_manager::MirPass>::run_pass
  15:     0x7f2191c0c4b0 - rustc_mir_transform[2c11676f69282928]::run_analysis_to_runtime_passes
  16:     0x7f2191ec74a5 - rustc_mir_transform[2c11676f69282928]::mir_drops_elaborated_and_const_checked
  17:     0x7f2191ec6e73 - rustc_query_impl[28a8675f0d90499e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[28a8675f0d90499e]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e5d78f1bcb31da04]::query::erase::Erased<[u8; 8usize]>>
  18:     0x7f2191eb746c - rustc_query_system[233cc3fa8f1a13f1]::query::plumbing::try_execute_query::<rustc_query_impl[28a8675f0d90499e]::DynamicConfig<rustc_data_structures[fc0b9671f81f22ab]::vec_cache::VecCache<rustc_span[24db630cafa28d18]::def_id::LocalDefId, rustc_middle[e5d78f1bcb31da04]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[233cc3fa8f1a13f1]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[28a8675f0d90499e]::plumbing::QueryCtxt, false>
  19:     0x7f2191eb6d4b - rustc_query_impl[28a8675f0d90499e]::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace
  20:     0x7f21926d7567 - rustc_interface[7235c659463d71e8]::passes::run_required_analyses
  21:     0x7f2192cc901e - rustc_interface[7235c659463d71e8]::passes::analysis
  22:     0x7f2192cc8ff3 - rustc_query_impl[28a8675f0d90499e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[28a8675f0d90499e]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e5d78f1bcb31da04]::query::erase::Erased<[u8; 0usize]>>
  23:     0x7f2192bdb3bd - rustc_query_system[233cc3fa8f1a13f1]::query::plumbing::try_execute_query::<rustc_query_impl[28a8675f0d90499e]::DynamicConfig<rustc_query_system[233cc3fa8f1a13f1]::query::caches::SingleCache<rustc_middle[e5d78f1bcb31da04]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[28a8675f0d90499e]::plumbing::QueryCtxt, false>
  24:     0x7f2192bdb0b8 - rustc_query_impl[28a8675f0d90499e]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  25:     0x7f2192f4850b - rustc_interface[7235c659463d71e8]::passes::create_and_enter_global_ctxt::<core[7209481d47dee51c]::option::Option<rustc_interface[7235c659463d71e8]::queries::Linker>, rustc_driver_impl[a1c67d496eb7e262]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  26:     0x7f2192d845b9 - rustc_interface[7235c659463d71e8]::interface::run_compiler::<(), rustc_driver_impl[a1c67d496eb7e262]::run_compiler::{closure#0}>::{closure#1}
  27:     0x7f2192d3518f - std[d6b00ef7faf64c8c]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[7235c659463d71e8]::util::run_in_thread_with_globals<rustc_interface[7235c659463d71e8]::util::run_in_thread_pool_with_globals<rustc_interface[7235c659463d71e8]::interface::run_compiler<(), rustc_driver_impl[a1c67d496eb7e262]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  28:     0x7f2192d35a6b - <<std[d6b00ef7faf64c8c]::thread::Builder>::spawn_unchecked_<rustc_interface[7235c659463d71e8]::util::run_in_thread_with_globals<rustc_interface[7235c659463d71e8]::util::run_in_thread_pool_with_globals<rustc_interface[7235c659463d71e8]::interface::run_compiler<(), rustc_driver_impl[a1c67d496eb7e262]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[7209481d47dee51c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  29:     0x7f2192d36e6b - std::sys::pal::unix::thread::Thread::new::thread_start::h78c682d656f9a9b8
  30:     0x7f218caa370a - <unknown>
  31:     0x7f218cb27aac - <unknown>
  32:                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: rustc 1.88.0-nightly (d4f880f8c 2025-04-08) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `with_positive::{closure#0}`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors; 3 warnings emitted

Some errors have detailed explanations: E0507, E0601, E0658.
For more information about an error, try `rustc --explain E0507`.

@rustbot label +F-type_alias_impl_trait

@matthiaskrgr matthiaskrgr 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 8, 2025
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` labels Apr 8, 2025
@matthiaskrgr
Copy link
Member Author

bisects to #138499

@matthiaskrgr
Copy link
Member Author

cc @lcnr

@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 17, 2025
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label May 2, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` 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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants