rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.69k stars 12.49k forks source link

ICE: index out of bounds #129075

Open matthiaskrgr opened 4 weeks ago

matthiaskrgr commented 4 weeks ago

auto-reduced (treereduce-rust):

struct Foo<T>([T; 2]);

impl<T: Default + Copy> Default for Foo<T> {
    fn default(&mut self) -> Self {
        Foo([Default::default(); 2])
    }
}

fn field_array() {
    let a: i32;
    let b;
    Foo([a, b]) = Default::default();
}
original code

original: ````rust #![allow(unused_variables)] use std::array::TryFromSliceError; use std::convert::TryInto; struct Zeroes; impl Into<[usize; 2]> for Zeroes { fn into(self) -> [usize; 2] { [0; 2] } } impl Into<[usize; 3]> for Zeroes { fn into(self) -> [usize; 3] { [0; 3] } } impl Into<[Option>; 48]> for Zeroes { fn into(self) -> [usize; 4] { [0; 4] } } fn zeroes_into() { let [a, b, c] = Zeroes.into(); let [d, e, f]: [_; 3] = Zeroes.into(); } fn array_try_from(x: &[usize]) -> Result { let [a, b] = d.succ().isoweekdate().1()?; Ok(a + b) } fn destructuring_assignment() { let a: i32; let b; [a, b] = Default::default(); } fn test_nested_array() { let a: [_; 3]; let b; //~^ ERROR type annotations needed [a, b] = Default::default(); } fn test_nested_array_type_hint() { let a: [_; 3]; let b; [a, b] = Default::default(); let _: i32 = b[1]; } fn test_working_nested_array() { let a: i32; [[a, _, _], _, _] = Default::default(); } struct Foo([T; 2]); impl Default for Foo { fn default(&mut self, (_,): (T,)) -> Self { Foo([Default::default(); 2]) } } fn field_array() { let a: i32; let b; Foo([a, b]) = Default::default(); } fn main() {} ````

Version information

rustc 1.82.0-nightly (e5b3e68ab 2024-08-13)
binary: rustc
commit-hash: e5b3e68abf170556b9d56c6f9028318e53c9f06b
commit-date: 2024-08-13
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0

Command: /home/matthias/.rustup/toolchains/master/bin/rustc -Zvalidate-mir -Zinline-mir=yes

Program output

``` error[E0601]: `main` function not found in crate `mvce` --> /tmp/icemaker_global_tempdir.ufzSPaPZx9Up/rustc_testrunner_tmpdir_reporting.doFpl6Nkk2VR/mvce.rs:13:2 | 13 | } | ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.ufzSPaPZx9Up/rustc_testrunner_tmpdir_reporting.doFpl6Nkk2VR/mvce.rs` error[E0185]: method `default` has a `&mut self` declaration in the impl, but not in the trait --> /tmp/icemaker_global_tempdir.ufzSPaPZx9Up/rustc_testrunner_tmpdir_reporting.doFpl6Nkk2VR/mvce.rs:4:5 | 4 | fn default(&mut self) -> Self { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&mut self` used in impl | = note: `default` from trait: `fn() -> Self` warning: variable `a` is assigned to, but never used --> /tmp/icemaker_global_tempdir.ufzSPaPZx9Up/rustc_testrunner_tmpdir_reporting.doFpl6Nkk2VR/mvce.rs:10:9 | 10 | let a: i32; | ^ | = note: consider using `_a` instead = note: `#[warn(unused_variables)]` on by default warning: variable `b` is assigned to, but never used --> /tmp/icemaker_global_tempdir.ufzSPaPZx9Up/rustc_testrunner_tmpdir_reporting.doFpl6Nkk2VR/mvce.rs:11:9 | 11 | let b; | ^ | = note: consider using `_b` instead warning: value assigned to `a` is never read --> /tmp/icemaker_global_tempdir.ufzSPaPZx9Up/rustc_testrunner_tmpdir_reporting.doFpl6Nkk2VR/mvce.rs:12:10 | 12 | Foo([a, b]) = Default::default(); | ^ | = help: maybe it is overwritten before being read? = note: `#[warn(unused_assignments)]` on by default warning: value assigned to `b` is never read --> /tmp/icemaker_global_tempdir.ufzSPaPZx9Up/rustc_testrunner_tmpdir_reporting.doFpl6Nkk2VR/mvce.rs:12:13 | 12 | Foo([a, b]) = Default::default(); | ^ | = help: maybe it is overwritten before being read? thread 'rustc' panicked at /rustc/e5b3e68abf170556b9d56c6f9028318e53c9f06b/compiler/rustc_middle/src/mir/tcx.rs:131:61: index out of bounds: the len is 11 but the index is 11 stack backtrace: 0: 0x71a82a9be6ad - ::fmt::hd8cddadc2f1356ba 1: 0x71a82b2049ef - core::fmt::write::hf4a4be5c7aa55e78 2: 0x71a82c1c5511 - std::io::Write::write_fmt::h937572d76c9c7a9b 3: 0x71a82a9c0d8b - std::panicking::default_hook::{{closure}}::h663ce340916a5919 4: 0x71a82a9c09fe - std::panicking::default_hook::h5cb270171c609139 5: 0x71a829b4b6c9 - std[c898dee7a900a719]::panicking::update_hook::>::{closure#0} 6: 0x71a82a9c16a7 - std::panicking::rust_panic_with_hook::h527dcb0b253a1e21 7: 0x71a82a9c1367 - std::panicking::begin_panic_handler::{{closure}}::hbc0a646a011dd19f 8: 0x71a82a9beb69 - std::sys::backtrace::__rust_end_short_backtrace::h44802a1bb26a785a 9: 0x71a82a9c1034 - rust_begin_unwind 10: 0x71a827f50563 - core::panicking::panic_fmt::hb546fe36be3a0f24 11: 0x71a828efc287 - core::panicking::panic_bounds_check::h90b5d213a1bed1e4 12: 0x71a82bb52baa - ::try_inlining 13: 0x71a82bb4fc89 - ::process_blocks 14: 0x71a82bb4fd09 - ::process_blocks 15: 0x71a82bb4f126 - ::run_pass 16: 0x71a82b201cd1 - rustc_mir_transform[9616e0e93931520b]::pass_manager::run_passes_inner 17: 0x71a82b7a1df2 - rustc_mir_transform[9616e0e93931520b]::optimized_mir 18: 0x71a82c143ddb - rustc_query_impl[52474172086763ba]::plumbing::__rust_begin_short_backtrace::> 19: 0x71a82b228434 - rustc_query_system[1f2263bc77e8d28d]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[52474172086763ba]::plumbing::QueryCtxt, false> 20: 0x71a82b2279df - rustc_query_impl[52474172086763ba]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace 21: 0x71a827f13204 - ::instance_mir 22: 0x71a82b9af306 - rustc_interface[922598e417aca69f]::passes::run_required_analyses 23: 0x71a82bd3611e - rustc_interface[922598e417aca69f]::passes::analysis 24: 0x71a82bd360f1 - rustc_query_impl[52474172086763ba]::plumbing::__rust_begin_short_backtrace::> 25: 0x71a82c18efae - rustc_query_system[1f2263bc77e8d28d]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[52474172086763ba]::plumbing::QueryCtxt, false> 26: 0x71a82c18ed0f - rustc_query_impl[52474172086763ba]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 27: 0x71a82bfced29 - rustc_interface[922598e417aca69f]::interface::run_compiler::, rustc_driver_impl[7bc6674bbf855457]::run_compiler::{closure#0}>::{closure#1} 28: 0x71a82bfb6690 - std[c898dee7a900a719]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[7bc6674bbf855457]::run_compiler::{closure#0}>::{closure#1}, core[57139b9ad86af3c3]::result::Result<(), rustc_span[6e02c34e35948369]::ErrorGuaranteed>>::{closure#0}, core[57139b9ad86af3c3]::result::Result<(), rustc_span[6e02c34e35948369]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[57139b9ad86af3c3]::result::Result<(), rustc_span[6e02c34e35948369]::ErrorGuaranteed>> 29: 0x71a82bfb6cfa - <::spawn_unchecked_, rustc_driver_impl[7bc6674bbf855457]::run_compiler::{closure#0}>::{closure#1}, core[57139b9ad86af3c3]::result::Result<(), rustc_span[6e02c34e35948369]::ErrorGuaranteed>>::{closure#0}, core[57139b9ad86af3c3]::result::Result<(), rustc_span[6e02c34e35948369]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[57139b9ad86af3c3]::result::Result<(), rustc_span[6e02c34e35948369]::ErrorGuaranteed>>::{closure#1} as core[57139b9ad86af3c3]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 30: 0x71a82bfb706b - std::sys::pal::unix::thread::Thread::new::thread_start::h2b4f313cc68cf720 31: 0x71a82d72139d - 32: 0x71a82d7a649c - 33: 0x0 - 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.82.0-nightly (e5b3e68ab 2024-08-13) running on x86_64-unknown-linux-gnu note: compiler flags: -Z validate-mir -Z inline-mir=yes -Z dump-mir-dir=dir query stack during panic: #0 [optimized_mir] optimizing MIR for `field_array` #1 [analysis] running analysis passes on this crate end of query stack error: aborting due to 2 previous errors; 4 warnings emitted Some errors have detailed explanations: E0185, E0601. For more information about an error, try `rustc --explain E0185`. ```

matthiaskrgr commented 4 weeks ago

128612 :/