Skip to content

ICE: upvar: assertion failed: 1 == 2 -Wrust-2021-incompatible-closure-captures #140011

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

Open
matthiaskrgr opened this issue Apr 18, 2025 · 1 comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

//@compile-flags: -Wrust-2021-incompatible-closure-captures
enum Either {
    One(XorShiftRng),
    Two(X),
}

struct X;

fn move_into_fnmut() {
    let x = Either::One(X);
    let y = || {
        let Either::Two(a) = x;
    };
}

original:

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

struct X;

fn move_into_fnmut() {
    let x = Either::One(X);
    let y = || {
        let Either::Two(a) = x;
    };
}

fn main() { }

Version information

rustc 1.88.0-nightly (1f76d219c 2025-04-17)
binary: rustc
commit-hash: 1f76d219c906f0112bb1872f33aa977164c53fa6
commit-date: 2025-04-17
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Possibly related line of code:

ty::Ref(..) => unreachable!(),
ty::RawPtr(..) => unreachable!(),
ty::Adt(def, args) => {
// Multi-variant enums are captured in entirety,
// which would've been handled in the case of single empty slice in `captured_by_move_projs`.
assert_eq!(def.variants().len(), 1);
// Only Field projections can be applied to a non-box Adt.
assert!(
captured_by_move_projs.iter().all(|projs| matches!(
projs.first().unwrap().kind,
ProjectionKind::Field(..)

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Wrust-2021-incompatible-closure-captures

Program output

error[E0412]: cannot find type `XorShiftRng` in this scope
 --> /tmp/icemaker_global_tempdir.mjs3HhQOcIiO/rustc_testrunner_tmpdir_reporting.JVHxPnPMCvzx/mvce.rs:2:9
  |
2 |     One(XorShiftRng),
  |         ^^^^^^^^^^^ not found in this scope

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


thread 'rustc' panicked at compiler/rustc_hir_typeck/src/upvar.rs:1616:17:
assertion `left == right` failed
  left: 2
 right: 1
stack backtrace:
   0:     0x74c9c96c4bf3 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h72d2f767860f01c8
   1:     0x74c9c9e05b07 - core::fmt::write::ha0040902920efb26
   2:     0x74c9cb297351 - std::io::Write::write_fmt::h92d425739cf7f0f8
   3:     0x74c9c96c4a52 - std::sys::backtrace::BacktraceLock::print::h60480fc7af7284f9
   4:     0x74c9c96c83ca - std::panicking::default_hook::{{closure}}::h0210b2339a694596
   5:     0x74c9c96c7f4f - std::panicking::default_hook::h26e462c1b992a8d3
   6:     0x74c9c8745753 - std[5360fa45f3745eb7]::panicking::update_hook::<alloc[3e73228144efd5c3]::boxed::Box<rustc_driver_impl[9f43b67c13dcf142]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x74c9c96c8c43 - std::panicking::rust_panic_with_hook::h9046e71ecea68928
   8:     0x74c9c96c893a - std::panicking::begin_panic_handler::{{closure}}::hb8579fcd3517556a
   9:     0x74c9c96c50c9 - std::sys::backtrace::__rust_end_short_backtrace::h7c2200761e8b2677
  10:     0x74c9c96c85fd - __rustc[5b4c3b5a2bd13629]::rust_begin_unwind
  11:     0x74c9c60863c0 - core::panicking::panic_fmt::h39077f0ed79e3d52
  12:     0x74c9c80c3eca - core::panicking::assert_failed_inner::hd76d8c96d70011e6
  13:     0x74c9c80c3df9 - core::panicking::assert_failed::he4657e61c1bba572
  14:     0x74c9c8af5f9a - <rustc_hir_typeck[19dd2fb0ef174692]::fn_ctxt::FnCtxt>::has_significant_drop_outside_of_captures
  15:     0x74c9c8af1fc4 - <rustc_hir_typeck[19dd2fb0ef174692]::fn_ctxt::FnCtxt>::perform_2229_migration_analysis
  16:     0x74c9ca6e0807 - <rustc_hir_typeck[19dd2fb0ef174692]::fn_ctxt::FnCtxt>::analyze_closure
  17:     0x74c9ca6b0052 - <rustc_hir_typeck[19dd2fb0ef174692]::upvar::InferBorrowKindVisitor as rustc_hir[5929cbe382679e99]::intravisit::Visitor>::visit_expr
  18:     0x74c9ca6aff58 - <rustc_hir_typeck[19dd2fb0ef174692]::upvar::InferBorrowKindVisitor as rustc_hir[5929cbe382679e99]::intravisit::Visitor>::visit_block
  19:     0x74c9ca6b332a - rustc_hir_typeck[19dd2fb0ef174692]::typeck_with_inspect::{closure#0}
  20:     0x74c9ca6b19b6 - rustc_query_impl[5554cc5a49e13358]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5554cc5a49e13358]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[be3fd842b5d62089]::query::erase::Erased<[u8; 8usize]>>
  21:     0x74c9ca071e6c - rustc_query_system[6a51e1997cb665e8]::query::plumbing::try_execute_query::<rustc_query_impl[5554cc5a49e13358]::DynamicConfig<rustc_data_structures[c6be5df131b5adc5]::vec_cache::VecCache<rustc_span[34967910c7e58b20]::def_id::LocalDefId, rustc_middle[be3fd842b5d62089]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[6a51e1997cb665e8]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[5554cc5a49e13358]::plumbing::QueryCtxt, false>
  22:     0x74c9ca0718cb - rustc_query_impl[5554cc5a49e13358]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  23:     0x74c9ca070348 - rustc_hir_analysis[4ccd349711354d63]::check_crate
  24:     0x74c9ca1fc074 - rustc_interface[ea4bb220888d6441]::passes::run_required_analyses
  25:     0x74c9cacc229e - rustc_interface[ea4bb220888d6441]::passes::analysis
  26:     0x74c9cacc2273 - rustc_query_impl[5554cc5a49e13358]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5554cc5a49e13358]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[be3fd842b5d62089]::query::erase::Erased<[u8; 0usize]>>
  27:     0x74c9cacc7d3d - rustc_query_system[6a51e1997cb665e8]::query::plumbing::try_execute_query::<rustc_query_impl[5554cc5a49e13358]::DynamicConfig<rustc_query_system[6a51e1997cb665e8]::query::caches::SingleCache<rustc_middle[be3fd842b5d62089]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[5554cc5a49e13358]::plumbing::QueryCtxt, false>
  28:     0x74c9cacc7a38 - rustc_query_impl[5554cc5a49e13358]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  29:     0x74c9caf4e0fe - rustc_interface[ea4bb220888d6441]::passes::create_and_enter_global_ctxt::<core[6a8fd511579d4332]::option::Option<rustc_interface[ea4bb220888d6441]::queries::Linker>, rustc_driver_impl[9f43b67c13dcf142]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  30:     0x74c9caf3c484 - rustc_interface[ea4bb220888d6441]::interface::run_compiler::<(), rustc_driver_impl[9f43b67c13dcf142]::run_compiler::{closure#0}>::{closure#1}
  31:     0x74c9caf2cab4 - std[5360fa45f3745eb7]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[ea4bb220888d6441]::util::run_in_thread_with_globals<rustc_interface[ea4bb220888d6441]::util::run_in_thread_pool_with_globals<rustc_interface[ea4bb220888d6441]::interface::run_compiler<(), rustc_driver_impl[9f43b67c13dcf142]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  32:     0x74c9caf2cef4 - <<std[5360fa45f3745eb7]::thread::Builder>::spawn_unchecked_<rustc_interface[ea4bb220888d6441]::util::run_in_thread_with_globals<rustc_interface[ea4bb220888d6441]::util::run_in_thread_pool_with_globals<rustc_interface[ea4bb220888d6441]::interface::run_compiler<(), rustc_driver_impl[9f43b67c13dcf142]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[6a8fd511579d4332]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x74c9caf2e2eb - std::sys::pal::unix::thread::Thread::new::thread_start::h7e071d267c3a6526
  34:     0x74c9c4ca370a - <unknown>
  35:     0x74c9c4d27aac - <unknown>
  36:                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 (1f76d219c 2025-04-17) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z dump-mir-dir=dir

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

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

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

smaller:

enum b {
    c(d),
    e(f),
}
struct f;
fn g() {
    let h;
    || b::e(a) = h;
}

@jieyouxu jieyouxu added the S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue label Apr 19, 2025
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) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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