Skip to content

[ICE]: Wrust-2021-incompatible-closure-captures #155497

Description

@matthiaskrgr

original:

//@compile-flags: -Wrust-2021-incompatible-closure-captures
struct Foo((u32, i128));

fn main() {
    type T = impl async FnOnce() -> T;
    let foo: T = Foo();
    let x = move || {
        let x = move || {
            let Foo((a, b)) = foo;
        };
    };
}

Version information

rustc 1.97.0-nightly (8da2d28cb 2026-04-18)
binary: rustc
commit-hash: 8da2d28cbd5a4e2b93e028e709afe09541671663
commit-date: 2026-04-18
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.2

Possibly related line of code:

paths_using_field,
)
})
}
// Anything else would be completely captured and therefore handled already.
_ => unreachable!(),
}
}
fn init_capture_kind_for_place(
&self,
place: &Place<'tcx>,

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

Program output

error: `async` trait bounds are only allowed in Rust 2018 or later
 --> /tmp/icemaker_global_tempdir.ZoarixqjDRq1/rustc_testrunner_tmpdir_reporting.C70SpvInghNQ/mvce.rs:4:19
  |
4 |     type T = impl async FnOnce() -> T;
  |                   ^^^^^
  |
  = help: pass `--edition 2024` to `rustc`
  = note: for more on editions, read https://doc.rust-lang.org/edition-guide

error[E0658]: `async` trait bounds are unstable
 --> /tmp/icemaker_global_tempdir.ZoarixqjDRq1/rustc_testrunner_tmpdir_reporting.C70SpvInghNQ/mvce.rs:4:19
  |
4 |     type T = impl async FnOnce() -> T;
  |                   ^^^^^
  |
  = note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
  = help: add `#![feature(async_trait_bounds)]` to the crate attributes to enable
  = note: this compiler was built on 2026-04-18; consider upgrading it if it is out of date
  = help: use the desugared name of the async trait, such as `AsyncFn`

error[E0658]: `impl Trait` in type aliases is unstable
 --> /tmp/icemaker_global_tempdir.ZoarixqjDRq1/rustc_testrunner_tmpdir_reporting.C70SpvInghNQ/mvce.rs:4:14
  |
4 |     type T = impl async FnOnce() -> 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 2026-04-18; consider upgrading it if it is out of date

error[E0061]: this struct takes 1 argument but 0 arguments were supplied
 --> /tmp/icemaker_global_tempdir.ZoarixqjDRq1/rustc_testrunner_tmpdir_reporting.C70SpvInghNQ/mvce.rs:5:18
  |
5 |     let foo: T = Foo();
  |                  ^^^-- argument #1 of type `(u32, i128)` is missing
  |
note: tuple struct defined here
 --> /tmp/icemaker_global_tempdir.ZoarixqjDRq1/rustc_testrunner_tmpdir_reporting.C70SpvInghNQ/mvce.rs:1:8
  |
1 | struct Foo((u32, i128));
  |        ^^^
help: provide the argument
  |
5 |     let foo: T = Foo(/* (u32, i128) */);
  |                      +++++++++++++++++

error[E0277]: the trait bound `Foo: AsyncFnOnce()` is not satisfied
 --> /tmp/icemaker_global_tempdir.ZoarixqjDRq1/rustc_testrunner_tmpdir_reporting.C70SpvInghNQ/mvce.rs:5:18
  |
5 |     let foo: T = Foo();
  |                  ^^^^^ unsatisfied trait bound
  |
help: the trait `AsyncFnOnce()` is not implemented for `Foo`
 --> /tmp/icemaker_global_tempdir.ZoarixqjDRq1/rustc_testrunner_tmpdir_reporting.C70SpvInghNQ/mvce.rs:1:1
  |
1 | struct Foo((u32, i128));
  | ^^^^^^^^^^

error[E0277]: the trait bound `Foo: AsyncFnOnce()` is not satisfied
 --> /tmp/icemaker_global_tempdir.ZoarixqjDRq1/rustc_testrunner_tmpdir_reporting.C70SpvInghNQ/mvce.rs:8:17
  |
8 |             let Foo((a, b)) = foo;
  |                 ^^^^^^^^^^^ unsatisfied trait bound
  |
help: the trait `AsyncFnOnce()` is not implemented for `Foo`
 --> /tmp/icemaker_global_tempdir.ZoarixqjDRq1/rustc_testrunner_tmpdir_reporting.C70SpvInghNQ/mvce.rs:1:1
  |
1 | struct Foo((u32, i128));
  | ^^^^^^^^^^


thread 'rustc' (2435430) panicked at /rustc-dev/8da2d28cbd5a4e2b93e028e709afe09541671663/compiler/rustc_hir_typeck/src/upvar.rs:1776:18:
internal error: entered unreachable code
stack backtrace:
   0:     0x7f14ce422ceb - <<std[d6a62db279dbae46]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[e86e8f32962a9819]::fmt::Display>::fmt
   1:     0x7f14cea2e808 - core[e86e8f32962a9819]::fmt::write
   2:     0x7f14ce439ce6 - <std[d6a62db279dbae46]::sys::stdio::unix::Stderr as std[d6a62db279dbae46]::io::Write>::write_fmt
   3:     0x7f14ce3f8f68 - std[d6a62db279dbae46]::panicking::default_hook::{closure#0}
   4:     0x7f14ce416353 - std[d6a62db279dbae46]::panicking::default_hook
   5:     0x7f14cd3db02c - std[d6a62db279dbae46]::panicking::update_hook::<alloc[26814c36517be32d]::boxed::Box<rustc_driver_impl[945e7c8a3fc176fa]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f14ce416632 - std[d6a62db279dbae46]::panicking::panic_with_hook
   7:     0x7f14ce3f905a - std[d6a62db279dbae46]::panicking::panic_handler::{closure#0}
   8:     0x7f14ce3efd69 - std[d6a62db279dbae46]::sys::backtrace::__rust_end_short_backtrace::<std[d6a62db279dbae46]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f14ce3faa8d - __rustc[3f76c9a779ba9221]::rust_begin_unwind
  10:     0x7f14caf8aa3c - core[e86e8f32962a9819]::panicking::panic_fmt
  11:     0x7f14cc2d3d52 - core[e86e8f32962a9819]::panicking::panic
  12:     0x7f14cd6f1d08 - <rustc_hir_typeck[1ebf63e3d4a70057]::fn_ctxt::FnCtxt>::has_significant_drop_outside_of_captures
  13:     0x7f14cd6ee7f1 - <rustc_hir_typeck[1ebf63e3d4a70057]::fn_ctxt::FnCtxt>::perform_2229_migration_analysis
  14:     0x7f14cf5fbf03 - <rustc_hir_typeck[1ebf63e3d4a70057]::fn_ctxt::FnCtxt>::analyze_closure
  15:     0x7f14ced0fe92 - <rustc_hir_typeck[1ebf63e3d4a70057]::upvar::InferBorrowKindVisitor as rustc_hir[364cc9694d698482]::intravisit::Visitor>::visit_expr
  16:     0x7f14ced0fd11 - <rustc_hir_typeck[1ebf63e3d4a70057]::upvar::InferBorrowKindVisitor as rustc_hir[364cc9694d698482]::intravisit::Visitor>::visit_block
  17:     0x7f14ced0fe6b - <rustc_hir_typeck[1ebf63e3d4a70057]::upvar::InferBorrowKindVisitor as rustc_hir[364cc9694d698482]::intravisit::Visitor>::visit_expr
  18:     0x7f14ced0fd11 - <rustc_hir_typeck[1ebf63e3d4a70057]::upvar::InferBorrowKindVisitor as rustc_hir[364cc9694d698482]::intravisit::Visitor>::visit_block
  19:     0x7f14cfc1418a - rustc_hir_typeck[1ebf63e3d4a70057]::typeck_with_inspect::{closure#0}
  20:     0x7f14cfc12570 - rustc_query_impl[a6166eb9fe0387cf]::query_impl::typeck_root::invoke_provider_fn::__rust_begin_short_backtrace
  21:     0x7f14ceb2be26 - rustc_query_impl[a6166eb9fe0387cf]::execution::try_execute_query::<rustc_data_structures[7b9148a745519926]::vec_cache::VecCache<rustc_span[63e5a877534af3f7]::def_id::LocalDefId, rustc_middle[253f0d05195ba05e]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[253f0d05195ba05e]::dep_graph::graph::DepNodeIndex>, false>
  22:     0x7f14ceb2b643 - rustc_query_impl[a6166eb9fe0387cf]::query_impl::typeck_root::execute_query_non_incr::__rust_end_short_backtrace
  23:     0x7f14cf03f7d8 - rustc_mir_build[d8e4297702baa306]::thir::pattern::check_match::check_match
  24:     0x7f14cf03ec1b - rustc_query_impl[a6166eb9fe0387cf]::query_impl::check_match::invoke_provider_fn::__rust_begin_short_backtrace
  25:     0x7f14cf33f4e6 - rustc_query_impl[a6166eb9fe0387cf]::execution::try_execute_query::<rustc_data_structures[7b9148a745519926]::vec_cache::VecCache<rustc_span[63e5a877534af3f7]::def_id::LocalDefId, rustc_middle[253f0d05195ba05e]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[253f0d05195ba05e]::dep_graph::graph::DepNodeIndex>, false>
  26:     0x7f14cf33f142 - rustc_query_impl[a6166eb9fe0387cf]::query_impl::check_match::execute_query_non_incr::__rust_end_short_backtrace
  27:     0x7f14cf046c49 - rustc_mir_build[d8e4297702baa306]::builder::build_mir_inner_impl
  28:     0x7f14cea0b7ea - rustc_mir_transform[5e6f23ecb9c29fca]::mir_built
  29:     0x7f14ceb2be26 - rustc_query_impl[a6166eb9fe0387cf]::execution::try_execute_query::<rustc_data_structures[7b9148a745519926]::vec_cache::VecCache<rustc_span[63e5a877534af3f7]::def_id::LocalDefId, rustc_middle[253f0d05195ba05e]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[253f0d05195ba05e]::dep_graph::graph::DepNodeIndex>, false>
  30:     0x7f14ceb2b943 - rustc_query_impl[a6166eb9fe0387cf]::query_impl::mir_built::execute_query_non_incr::__rust_end_short_backtrace
  31:     0x7f14cea3856e - rustc_mir_transform[5e6f23ecb9c29fca]::ffi_unwind_calls::has_ffi_unwind_calls
  32:     0x7f14cea37fd9 - rustc_query_impl[a6166eb9fe0387cf]::query_impl::has_ffi_unwind_calls::invoke_provider_fn::__rust_begin_short_backtrace
  33:     0x7f14cf33f4e6 - rustc_query_impl[a6166eb9fe0387cf]::execution::try_execute_query::<rustc_data_structures[7b9148a745519926]::vec_cache::VecCache<rustc_span[63e5a877534af3f7]::def_id::LocalDefId, rustc_middle[253f0d05195ba05e]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[253f0d05195ba05e]::dep_graph::graph::DepNodeIndex>, false>
  34:     0x7f14cf33f0b6 - rustc_query_impl[a6166eb9fe0387cf]::query_impl::has_ffi_unwind_calls::execute_query_non_incr::__rust_end_short_backtrace
  35:     0x7f14cf4d6d1c - rustc_mir_transform[5e6f23ecb9c29fca]::mir_promoted
  36:     0x7f14cf4d6ba0 - rustc_query_impl[a6166eb9fe0387cf]::query_impl::mir_promoted::invoke_provider_fn::__rust_begin_short_backtrace
  37:     0x7f14cf3cebb7 - rustc_query_impl[a6166eb9fe0387cf]::execution::try_execute_query::<rustc_data_structures[7b9148a745519926]::vec_cache::VecCache<rustc_span[63e5a877534af3f7]::def_id::LocalDefId, rustc_middle[253f0d05195ba05e]::query::erase::ErasedData<[u8; 16usize]>, rustc_middle[253f0d05195ba05e]::dep_graph::graph::DepNodeIndex>, false>
  38:     0x7f14cf3ce743 - rustc_query_impl[a6166eb9fe0387cf]::query_impl::mir_promoted::execute_query_non_incr::__rust_end_short_backtrace
  39:     0x7f14cfb1f6b3 - rustc_borrowck[6886b9bd56e1eb31]::mir_borrowck
  40:     0x7f14cfb1f62d - rustc_query_impl[a6166eb9fe0387cf]::query_impl::mir_borrowck::invoke_provider_fn::__rust_begin_short_backtrace
  41:     0x7f14ceb2be26 - rustc_query_impl[a6166eb9fe0387cf]::execution::try_execute_query::<rustc_data_structures[7b9148a745519926]::vec_cache::VecCache<rustc_span[63e5a877534af3f7]::def_id::LocalDefId, rustc_middle[253f0d05195ba05e]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[253f0d05195ba05e]::dep_graph::graph::DepNodeIndex>, false>
  42:     0x7f14ceb2b4c3 - rustc_query_impl[a6166eb9fe0387cf]::query_impl::mir_borrowck::execute_query_non_incr::__rust_end_short_backtrace
  43:     0x7f14cd563987 - <rustc_hir_analysis[1a46041d384d7932]::collect::type_of::opaque::TaitConstraintLocator>::check
  44:     0x7f14cd5a7361 - rustc_hir_analysis[1a46041d384d7932]::collect::type_of::opaque::find_opaque_ty_constraints_for_tait
  45:     0x7f14d0806822 - rustc_hir_analysis[1a46041d384d7932]::collect::type_of::type_of_opaque.cold
  46:     0x7f14cea143cd - rustc_query_impl[a6166eb9fe0387cf]::execution::try_execute_query::<rustc_middle[253f0d05195ba05e]::query::caches::DefIdCache<rustc_middle[253f0d05195ba05e]::query::erase::ErasedData<[u8; 8usize]>>, false>
  47:     0x7f14cfbbed98 - rustc_query_impl[a6166eb9fe0387cf]::query_impl::type_of_opaque::execute_query_non_incr::__rust_end_short_backtrace
  48:     0x7f14ceedda6c - rustc_hir_analysis[1a46041d384d7932]::collect::type_of::type_of
  49:     0x7f14cece1726 - rustc_query_impl[a6166eb9fe0387cf]::query_impl::type_of::invoke_provider_fn::__rust_begin_short_backtrace
  50:     0x7f14cea143cd - rustc_query_impl[a6166eb9fe0387cf]::execution::try_execute_query::<rustc_middle[253f0d05195ba05e]::query::caches::DefIdCache<rustc_middle[253f0d05195ba05e]::query::erase::ErasedData<[u8; 8usize]>>, false>
  51:     0x7f14cea13f50 - rustc_query_impl[a6166eb9fe0387cf]::query_impl::type_of::execute_query_non_incr::__rust_end_short_backtrace
  52:     0x7f14cf9e7c50 - rustc_hir_analysis[1a46041d384d7932]::check::check::check_opaque
  53:     0x7f14cf348e44 - rustc_hir_analysis[1a46041d384d7932]::check::check::check_item_type
  54:     0x7f14cf33ff1c - rustc_hir_analysis[1a46041d384d7932]::check::wfcheck::check_well_formed
  55:     0x7f14cf33fef9 - rustc_query_impl[a6166eb9fe0387cf]::query_impl::check_well_formed::invoke_provider_fn::__rust_begin_short_backtrace
  56:     0x7f14cf33f4e6 - rustc_query_impl[a6166eb9fe0387cf]::execution::try_execute_query::<rustc_data_structures[7b9148a745519926]::vec_cache::VecCache<rustc_span[63e5a877534af3f7]::def_id::LocalDefId, rustc_middle[253f0d05195ba05e]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[253f0d05195ba05e]::dep_graph::graph::DepNodeIndex>, false>
  57:     0x7f14cf33f27b - rustc_query_impl[a6166eb9fe0387cf]::query_impl::check_well_formed::execute_query_non_incr::__rust_end_short_backtrace
  58:     0x7f14cf33b4c6 - rustc_hir_analysis[1a46041d384d7932]::check::wfcheck::check_type_wf
  59:     0x7f14cf33b353 - rustc_query_impl[a6166eb9fe0387cf]::query_impl::check_type_wf::invoke_provider_fn::__rust_begin_short_backtrace
  60:     0x7f14cfbb7bd0 - rustc_query_impl[a6166eb9fe0387cf]::execution::try_execute_query::<rustc_middle[253f0d05195ba05e]::query::caches::SingleCache<rustc_middle[253f0d05195ba05e]::query::erase::ErasedData<[u8; 1usize]>>, false>
  61:     0x7f14cfbb79a9 - rustc_query_impl[a6166eb9fe0387cf]::query_impl::check_type_wf::execute_query_non_incr::__rust_end_short_backtrace
  62:     0x7f14cf03c05b - rustc_hir_analysis[1a46041d384d7932]::check_crate
  63:     0x7f14cf8f2567 - rustc_interface[1d873664835f04c7]::passes::analysis
  64:     0x7f14cfbb5449 - rustc_query_impl[a6166eb9fe0387cf]::execution::try_execute_query::<rustc_middle[253f0d05195ba05e]::query::caches::SingleCache<rustc_middle[253f0d05195ba05e]::query::erase::ErasedData<[u8; 0usize]>>, false>
  65:     0x7f14cfbb50a9 - rustc_query_impl[a6166eb9fe0387cf]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  66:     0x7f14cfb9386d - rustc_interface[1d873664835f04c7]::interface::run_compiler::<(), rustc_driver_impl[945e7c8a3fc176fa]::run_compiler::{closure#0}>::{closure#1}
  67:     0x7f14cfb6b28a - std[d6a62db279dbae46]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[1d873664835f04c7]::util::run_in_thread_with_globals<rustc_interface[1d873664835f04c7]::util::run_in_thread_pool_with_globals<rustc_interface[1d873664835f04c7]::interface::run_compiler<(), rustc_driver_impl[945e7c8a3fc176fa]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  68:     0x7f14cfb6b96d - <std[d6a62db279dbae46]::thread::lifecycle::spawn_unchecked<rustc_interface[1d873664835f04c7]::util::run_in_thread_with_globals<rustc_interface[1d873664835f04c7]::util::run_in_thread_pool_with_globals<rustc_interface[1d873664835f04c7]::interface::run_compiler<(), rustc_driver_impl[945e7c8a3fc176fa]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[e86e8f32962a9819]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  69:     0x7f14cfb6c7ec - <std[d6a62db279dbae46]::sys::thread::unix::Thread>::new::thread_start
  70:     0x7f14c96a597a - <unknown>
  71:     0x7f14c97292bc - <unknown>
  72:                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.97.0-nightly (8da2d28cb 2026-04-18) running on x86_64-unknown-linux-gnu

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

query stack during panic:
#0 [typeck_root] type-checking `main`
#1 [check_match] match-checking `main`
#2 [mir_built] building MIR for `main`
#3 [has_ffi_unwind_calls] checking if `main` contains FFI-unwind calls
#4 [mir_promoted] promoting constants in MIR for `main`
#5 [mir_borrowck] borrow-checking `main`
#6 [type_of_opaque] computing type of opaque `main::T::{opaque#0}`
#7 [type_of] computing type of `main::T::{opaque#0}`
#8 [check_well_formed] checking that `main::T::{opaque#0}` is well-formed
#9 [check_type_wf] checking that types are well-formed
#10 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 6 previous errors

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

Activity

  1. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Apr 18, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Apr 18, 2026
  3. matthiaskrgr commented on Apr 18, 2026

    @matthiaskrgr
    MemberAuthor

    without errors:

    #![feature(type_alias_impl_trait)]
    #![warn(rust_2021_incompatible_closure_captures)]
    struct Foo(());
    fn main() {
        type T = impl Sized;
        let foo: T = todo!();
        let x = ();
        (move || Foo(x) = foo)()
    }

    ICEs with edition 2015, 2018 but not 2021 or later
    bisects to nightly-2021-07-08
    EDIT: the lint was renamed in this nightly 😒

    with #![warn(disjoint_capture_migration)]
    this bisects to nightly-2021-05-13

  4. added
    S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
    S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 7, 2026
  5. added 2 commits that reference this issue on Oct 5, 2026
  6. added a commit that references this issue on Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions