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: index out of bounds, -Wrust-2021-incompatible-closure-capture #109812

Closed
matthiaskrgr opened this issue Mar 31, 2023 · 1 comment · Fixed by #126320
Closed

ICE: index out of bounds, -Wrust-2021-incompatible-closure-capture #109812

matthiaskrgr opened this issue Mar 31, 2023 · 1 comment · Fixed by #126320
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

Code

enum Either {
    One(X),
    Two(X),
}

struct X(Y);

struct Y;

fn move_into_fnmut() {
    let x = X(Y);

    consume_fnmut(|| {
        let Either::Two(ref mut _t) = x;

        let X(mut _t) = x;
    });
}

Meta

rustc --version --verbose:

rustc 1.70.0-nightly (ec2f40c6b 2023-03-30)
binary: rustc
commit-hash: ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b
commit-date: 2023-03-30
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 16.0.0

Error output

rustc -Wrust-2021-incompatible-closure-capture treereduce.out

error[E0601]: `main` function not found in crate `treereduce`
  --> treereduce.out:18:2
   |
18 | }
   |  ^ consider adding a `main` function to `treereduce.out`

error[E0308]: mismatched types
  --> treereduce.out:14:13
   |
14 |         let Either::Two(ref mut _t) = x;
   |             ^^^^^^^^^^^^^^^^^^^^^^^   - this expression has type `X`
   |             |
   |             expected `X`, found `Either`

error[E0425]: cannot find function `consume_fnmut` in this scope
  --> treereduce.out:13:5
   |
13 |     consume_fnmut(|| {
   |     ^^^^^^^^^^^^^ not found in this scope
Backtrace

thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1', compiler/rustc_middle/src/ty/adt.rs:177:10
stack backtrace:
   0:     0x7f90bd29ae8a - std::backtrace_rs::backtrace::libunwind::trace::h0800f724f14b9f23
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f90bd29ae8a - std::backtrace_rs::backtrace::trace_unsynchronized::heb729c2b48914e5d
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f90bd29ae8a - std::sys_common::backtrace::_print_fmt::hfea18c777a6816a8
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f90bd29ae8a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5b335f1b57b7cfd3
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f90bd2fee6f - core::fmt::write::hfc269b47768b84d6
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/core/src/fmt/mod.rs:1254:17
   5:     0x7f90bd28d9c5 - std::io::Write::write_fmt::h1d662a9c8dd6348d
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/std/src/io/mod.rs:1698:15
   6:     0x7f90bd29ac55 - std::sys_common::backtrace::_print::h077a497ebae0e284
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f90bd29ac55 - std::sys_common::backtrace::print::h4c1bfafb31892c37
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f90bd29d8fe - std::panicking::default_hook::{{closure}}::h1d180e0dd97821e1
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/std/src/panicking.rs:269:22
   9:     0x7f90bd29d6a5 - std::panicking::default_hook::hb57aa318320cb549
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/std/src/panicking.rs:288:9
  10:     0x7f90bc084795 - rustc_driver_impl[5ba0129e8085a63c]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f90bd29e0f4 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h3b37cd4b5b400fd5
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/alloc/src/boxed.rs:1990:9
  12:     0x7f90bd29e0f4 - std::panicking::rust_panic_with_hook::h9f9047c578e712fa
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/std/src/panicking.rs:694:13
  13:     0x7f90bd29de69 - std::panicking::begin_panic_handler::{{closure}}::h65c68fe10fd36269
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/std/src/panicking.rs:581:13
  14:     0x7f90bd29b2f6 - std::sys_common::backtrace::__rust_end_short_backtrace::h01858bd16434bb8d
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/std/src/sys_common/backtrace.rs:150:18
  15:     0x7f90bd29dbc2 - rust_begin_unwind
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/std/src/panicking.rs:577:5
  16:     0x7f90bd2fb273 - core::panicking::panic_fmt::h63711dd7e9b0b59a
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/core/src/panicking.rs:67:14
  17:     0x7f90bd2fb3e2 - core::panicking::panic_bounds_check::h75e67454168bf3b9
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/core/src/panicking.rs:162:5
  18:     0x7f90bc5f56a9 - rustc_middle[a72f0da90161fe4d]::ty::closure::place_to_string_for_capture
  19:     0x7f90bb4c696b - <rustc_hir_typeck[80b0682908fd489]::fn_ctxt::FnCtxt>::analyze_closure
  20:     0x7f90ba128ceb - <rustc_hir_typeck[80b0682908fd489]::upvar::InferBorrowKindVisitor as rustc_hir[769709ae1002f61b]::intravisit::Visitor>::visit_expr
  21:     0x7f90ba128692 - <rustc_hir_typeck[80b0682908fd489]::upvar::InferBorrowKindVisitor as rustc_hir[769709ae1002f61b]::intravisit::Visitor>::visit_expr
  22:     0x7f90ba128aeb - <rustc_hir_typeck[80b0682908fd489]::upvar::InferBorrowKindVisitor as rustc_hir[769709ae1002f61b]::intravisit::Visitor>::visit_expr
  23:     0x7f90baf6be1b - rustc_hir_typeck[80b0682908fd489]::typeck
  24:     0x7f90ba1b7113 - rustc_query_system[c2820fdbf5c6d6ca]::query::plumbing::try_execute_query::<rustc_query_impl[9d23c39401f72dce]::queries::typeck, rustc_query_impl[9d23c39401f72dce]::plumbing::QueryCtxt>
  25:     0x7f90bb7d166b - rustc_data_structures[2fae5ecf9dd28fbb]::sync::par_for_each_in::<&[rustc_span[fd4f398dc0172457]::def_id::LocalDefId], <rustc_middle[a72f0da90161fe4d]::hir::map::Map>::par_body_owners<rustc_hir_typeck[80b0682908fd489]::typeck_item_bodies::{closure#0}>::{closure#0}>
  26:     0x7f90bb7d143f - rustc_hir_typeck[80b0682908fd489]::typeck_item_bodies
  27:     0x7f90bb83cab7 - rustc_query_system[c2820fdbf5c6d6ca]::query::plumbing::try_execute_query::<rustc_query_impl[9d23c39401f72dce]::queries::typeck_item_bodies, rustc_query_impl[9d23c39401f72dce]::plumbing::QueryCtxt>
  28:     0x7f90bb83c7cc - <rustc_query_impl[9d23c39401f72dce]::Queries as rustc_middle[a72f0da90161fe4d]::ty::query::QueryEngine>::typeck_item_bodies
  29:     0x7f90bb4e197f - <rustc_session[173a7fb0306a5cb1]::session::Session>::time::<(), rustc_hir_analysis[d7ef42721b387ff3]::check_crate::{closure#7}>
  30:     0x7f90bb4de3f7 - rustc_hir_analysis[d7ef42721b387ff3]::check_crate
  31:     0x7f90bb4d8241 - rustc_interface[415d18af8a4706e7]::passes::analysis
  32:     0x7f90bb83bb82 - rustc_query_system[c2820fdbf5c6d6ca]::query::plumbing::try_execute_query::<rustc_query_impl[9d23c39401f72dce]::queries::analysis, rustc_query_impl[9d23c39401f72dce]::plumbing::QueryCtxt>
  33:     0x7f90bb83b880 - <rustc_query_impl[9d23c39401f72dce]::Queries as rustc_middle[a72f0da90161fe4d]::ty::query::QueryEngine>::analysis
  34:     0x7f90bb1ff79e - <rustc_interface[415d18af8a4706e7]::queries::QueryResult<&rustc_middle[a72f0da90161fe4d]::ty::context::GlobalCtxt>>::enter::<core[ad7470cf32ab1c97]::result::Result<(), rustc_span[fd4f398dc0172457]::ErrorGuaranteed>, rustc_driver_impl[5ba0129e8085a63c]::run_compiler::{closure#1}::{closure#2}::{closure#4}>
  35:     0x7f90bb1fe33e - <rustc_interface[415d18af8a4706e7]::interface::Compiler>::enter::<rustc_driver_impl[5ba0129e8085a63c]::run_compiler::{closure#1}::{closure#2}, core[ad7470cf32ab1c97]::result::Result<core[ad7470cf32ab1c97]::option::Option<rustc_interface[415d18af8a4706e7]::queries::Linker>, rustc_span[fd4f398dc0172457]::ErrorGuaranteed>>
  36:     0x7f90bb1fc4f1 - rustc_span[fd4f398dc0172457]::with_source_map::<core[ad7470cf32ab1c97]::result::Result<(), rustc_span[fd4f398dc0172457]::ErrorGuaranteed>, rustc_interface[415d18af8a4706e7]::interface::run_compiler<core[ad7470cf32ab1c97]::result::Result<(), rustc_span[fd4f398dc0172457]::ErrorGuaranteed>, rustc_driver_impl[5ba0129e8085a63c]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  37:     0x7f90bb1fba9f - std[30ef443cf2df054a]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[415d18af8a4706e7]::util::run_in_thread_pool_with_globals<rustc_interface[415d18af8a4706e7]::interface::run_compiler<core[ad7470cf32ab1c97]::result::Result<(), rustc_span[fd4f398dc0172457]::ErrorGuaranteed>, rustc_driver_impl[5ba0129e8085a63c]::run_compiler::{closure#1}>::{closure#0}, core[ad7470cf32ab1c97]::result::Result<(), rustc_span[fd4f398dc0172457]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ad7470cf32ab1c97]::result::Result<(), rustc_span[fd4f398dc0172457]::ErrorGuaranteed>>
  38:     0x7f90bb91934e - <<std[30ef443cf2df054a]::thread::Builder>::spawn_unchecked_<rustc_interface[415d18af8a4706e7]::util::run_in_thread_pool_with_globals<rustc_interface[415d18af8a4706e7]::interface::run_compiler<core[ad7470cf32ab1c97]::result::Result<(), rustc_span[fd4f398dc0172457]::ErrorGuaranteed>, rustc_driver_impl[5ba0129e8085a63c]::run_compiler::{closure#1}>::{closure#0}, core[ad7470cf32ab1c97]::result::Result<(), rustc_span[fd4f398dc0172457]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ad7470cf32ab1c97]::result::Result<(), rustc_span[fd4f398dc0172457]::ErrorGuaranteed>>::{closure#1} as core[ad7470cf32ab1c97]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  39:     0x7f90bd2a81d5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6e08d5234042fb15
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/alloc/src/boxed.rs:1976:9
  40:     0x7f90bd2a81d5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h2c5056bcb5d46eb1
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/alloc/src/boxed.rs:1976:9
  41:     0x7f90bd2a81d5 - std::sys::unix::thread::Thread::new::thread_start::hbc95b3c4a4c1dd3a
                               at /rustc/ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b/library/std/src/sys/unix/thread.rs:108:17
  42:     0x7f90b8c66bb5 - <unknown>
  43:     0x7f90b8ce8d90 - <unknown>
  44:                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: rustc 1.70.0-nightly (ec2f40c6b 2023-03-30) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `move_into_fnmut`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

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

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Mar 31, 2023
@matthiaskrgr
Copy link
Member Author

searched toolchains nightly-2021-07-01 through nightly-2023-03-31


Regression in nightly-2021-07-12


matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 27, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 28, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 28, 2024
blyxyas pushed a commit to blyxyas/rust that referenced this issue Apr 28, 2024
fmease added a commit to fmease/rust that referenced this issue Jun 13, 2024
Avoid ICES after reporting errors on erroneous patterns

fixes rust-lang#109812
fixes rust-lang#125914
fixes rust-lang#124004
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 13, 2024
Avoid ICES after reporting errors on erroneous patterns

fixes rust-lang#109812
fixes rust-lang#125914
fixes rust-lang#124004
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 13, 2024
Avoid ICES after reporting errors on erroneous patterns

fixes rust-lang#109812
fixes rust-lang#125914
fixes rust-lang#124004
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 13, 2024
Avoid ICES after reporting errors on erroneous patterns

fixes rust-lang#109812
fixes rust-lang#125914
fixes rust-lang#124004
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 13, 2024
Avoid ICES after reporting errors on erroneous patterns

fixes rust-lang#109812
fixes rust-lang#125914
fixes rust-lang#124004
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 14, 2024
Avoid ICES after reporting errors on erroneous patterns

fixes rust-lang#109812
fixes rust-lang#125914
fixes rust-lang#124004
@bors bors closed this as completed in 2b3fb62 Jun 14, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 14, 2024
Rollup merge of rust-lang#126320 - oli-obk:pat_ice, r=lcnr

Avoid ICES after reporting errors on erroneous patterns

fixes rust-lang#109812
fixes rust-lang#125914
fixes rust-lang#124004
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. 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.

1 participant