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: fn_ctxt: index out of bounds #128848

Open matthiaskrgr opened 1 month ago

matthiaskrgr commented 1 month ago

auto-reduced (treereduce-rust):

trait A<T> {}

fn f<T, U, V: A<T>>(i: V, arena: T, k: U) -> (T, U) {
    f.call_once(j, k)
}

original:

trait A<T> {
    fn g<U>(&self, x: T, y: U) -> (T, U) { (x, y) }
}

impl From<I> for i32 { }
impl<EncodedValue> A<T> for u32 { }

fn f<T, U, V: A<T>>(i: V, arena: T, k: U) -> (T, U) {
    f.call_once(j, k)
}

pub fn main () {
    assert_eq!(f(0, 1, 2), (1, 2));
    assert_eq!(f(0, 1, 2), (1, 2));
}

Version information

rustc 1.82.0-nightly (2048386fe 2024-08-08)
binary: rustc
commit-hash: 2048386fe2898febe7315c0feb915458e41c7aa5
commit-date: 2024-08-08
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0

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

Program output

``` error[E0425]: cannot find value `j` in this scope --> /tmp/icemaker_global_tempdir.GCP2eBzpwgpY/rustc_testrunner_tmpdir_reporting.asPRKVXEGOYI/mvce.rs:4:17 | 4 | f.call_once(j, k) | ^ not found in this scope error[E0601]: `main` function not found in crate `mvce` --> /tmp/icemaker_global_tempdir.GCP2eBzpwgpY/rustc_testrunner_tmpdir_reporting.asPRKVXEGOYI/mvce.rs:5:2 | 5 | } | ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.GCP2eBzpwgpY/rustc_testrunner_tmpdir_reporting.asPRKVXEGOYI/mvce.rs` error[E0658]: use of unstable library feature 'fn_traits' --> /tmp/icemaker_global_tempdir.GCP2eBzpwgpY/rustc_testrunner_tmpdir_reporting.asPRKVXEGOYI/mvce.rs:4:7 | 4 | f.call_once(j, k) | ^^^^^^^^^ | = note: see issue #29625 for more information = help: add `#![feature(fn_traits)]` to the crate attributes to enable = note: this compiler was built on 2024-08-08; consider upgrading it if it is out of date thread 'rustc' panicked at compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs:2289:46: index out of bounds: the len is 1 but the index is 1 stack backtrace: 0: 0x7e97171eab0d - std::backtrace_rs::backtrace::libunwind::trace::h288a87c5e2679186 at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5 1: 0x7e97171eab0d - std::backtrace_rs::backtrace::trace_unsynchronized::h5284ad94e8c74688 at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7e97171eab0d - std::sys::backtrace::_print_fmt::h371adc3f02dab1dd at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/std/src/sys/backtrace.rs:66:9 3: 0x7e97171eab0d - ::fmt::h148e7d8e87bab30f at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/std/src/sys/backtrace.rs:39:26 4: 0x7e971723b29b - core::fmt::rt::Argument::fmt::h7d54e75d5909de1b at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/core/src/fmt/rt.rs:173:76 5: 0x7e971723b29b - core::fmt::write::hf6482455a45a91c7 at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/core/src/fmt/mod.rs:1178:21 6: 0x7e97171de9a3 - std::io::Write::write_fmt::h78337f43013967dc at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/std/src/io/mod.rs:1823:15 7: 0x7e97171ed302 - std::sys::backtrace::BacktraceLock::print::he76ad41bfebe12ae at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/std/src/sys/backtrace.rs:42:9 8: 0x7e97171ed302 - std::panicking::default_hook::{{closure}}::hea2fb4697dfb5a9e at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/std/src/panicking.rs:266:22 9: 0x7e97171ecf6e - std::panicking::default_hook::h1dd19741d2e30ca9 at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/std/src/panicking.rs:293:9 10: 0x7e97136ba397 - std[3ddd7f8965915055]::panicking::update_hook::>::{closure#0} 11: 0x7e97171edcf2 - as core::ops::function::Fn>::call::h0b220dc3792e0071 at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/alloc/src/boxed.rs:2164:9 12: 0x7e97171edcf2 - std::panicking::rust_panic_with_hook::h31e66c1e0f0e6e18 at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/std/src/panicking.rs:805:13 13: 0x7e97171ed9a7 - std::panicking::begin_panic_handler::{{closure}}::h1057116e4a630d6a at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/std/src/panicking.rs:671:13 14: 0x7e97171eaff9 - std::sys::backtrace::__rust_end_short_backtrace::h943392b86d4267f1 at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/std/src/sys/backtrace.rs:170:18 15: 0x7e97171ed634 - rust_begin_unwind at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/std/src/panicking.rs:662:5 16: 0x7e97172378f3 - core::panicking::panic_fmt::h8f072a14c223852d at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/core/src/panicking.rs:74:14 17: 0x7e9717237ae7 - core::panicking::panic_bounds_check::he6402fc016b56f3d at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/core/src/panicking.rs:276:5 18: 0x7e97139cf86a - ::label_fn_like 19: 0x7e97139c7356 - ::report_arg_errors 20: 0x7e97114bd534 - ::check_method_argument_types 21: 0x7e971550403c - ::check_expr_with_expectation_and_args 22: 0x7e97154fba4b - ::check_block_with_expected 23: 0x7e97155032d8 - ::check_expr_with_expectation_and_args 24: 0x7e97154de180 - rustc_hir_typeck[dc91aa33eceb2355]::check::check_fn 25: 0x7e97154c08f7 - rustc_hir_typeck[dc91aa33eceb2355]::typeck 26: 0x7e97154c02b3 - rustc_query_impl[d0e7c8c52ee208c5]::plumbing::__rust_begin_short_backtrace::> 27: 0x7e9714f633f5 - rustc_query_system[bcd77f19768ca8fb]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[d0e7c8c52ee208c5]::plumbing::QueryCtxt, false> 28: 0x7e9714f625e3 - rustc_query_impl[d0e7c8c52ee208c5]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace 29: 0x7e9714f62200 - ::par_body_owners::::{closure#0} 30: 0x7e9714f5ffec - rustc_hir_analysis[f363d87ce7e00737]::check_crate 31: 0x7e9714f55995 - rustc_interface[ecbe5e558f1e13b6]::passes::analysis 32: 0x7e9714f55547 - rustc_query_impl[d0e7c8c52ee208c5]::plumbing::__rust_begin_short_backtrace::> 33: 0x7e9715be502e - rustc_query_system[bcd77f19768ca8fb]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[d0e7c8c52ee208c5]::plumbing::QueryCtxt, false> 34: 0x7e9715be4d8f - rustc_query_impl[d0e7c8c52ee208c5]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 35: 0x7e9715a5d260 - rustc_interface[ecbe5e558f1e13b6]::interface::run_compiler::, rustc_driver_impl[a075302d1f094aad]::run_compiler::{closure#0}>::{closure#1} 36: 0x7e971596a489 - std[3ddd7f8965915055]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[a075302d1f094aad]::run_compiler::{closure#0}>::{closure#1}, core[d8d378ef57b379bb]::result::Result<(), rustc_span[d8ab92baa90519c6]::ErrorGuaranteed>>::{closure#0}, core[d8d378ef57b379bb]::result::Result<(), rustc_span[d8ab92baa90519c6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d8d378ef57b379bb]::result::Result<(), rustc_span[d8ab92baa90519c6]::ErrorGuaranteed>> 37: 0x7e971596a232 - <::spawn_unchecked_, rustc_driver_impl[a075302d1f094aad]::run_compiler::{closure#0}>::{closure#1}, core[d8d378ef57b379bb]::result::Result<(), rustc_span[d8ab92baa90519c6]::ErrorGuaranteed>>::{closure#0}, core[d8d378ef57b379bb]::result::Result<(), rustc_span[d8ab92baa90519c6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d8d378ef57b379bb]::result::Result<(), rustc_span[d8ab92baa90519c6]::ErrorGuaranteed>>::{closure#1} as core[d8d378ef57b379bb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 38: 0x7e97171f7a0b - as core::ops::function::FnOnce>::call_once::h8531124d63bf03d4 at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/alloc/src/boxed.rs:2150:9 39: 0x7e97171f7a0b - as core::ops::function::FnOnce>::call_once::h14280c2e7cc937ab at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/alloc/src/boxed.rs:2150:9 40: 0x7e97171f7a0b - std::sys::pal::unix::thread::Thread::new::thread_start::hfbbba69bca48c3db at /rustc/2048386fe2898febe7315c0feb915458e41c7aa5/library/std/src/sys/pal/unix/thread.rs:110:17 41: 0x7e97100a6ded - 42: 0x7e971012a0dc - 43: 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 (2048386fe 2024-08-08) running on x86_64-unknown-linux-gnu query stack during panic: #0 [typeck] type-checking `f` #1 [analysis] running analysis passes on this crate end of query stack error: aborting due to 3 previous errors Some errors have detailed explanations: E0425, E0601, E0658. For more information about an error, try `rustc --explain E0425`. ```

matthiaskrgr commented 1 month ago

smaller:

trait A<T> {}

fn f<V: A<T>>(i: V, _x: V, k: V)  {
    f.call_once()
}
matthiaskrgr commented 1 month ago

Regression in nightly-2024-04-04 Regression in 4fd4797c2654977f545c9a91e2aa4e6cdbb38919

121595

compiler-errors commented 1 month ago

more minimal:

fn f<T>(a: T, b: T, c: T)  {
    f.call_once()
}
jder commented 3 weeks ago

@rustbot claim