rust-lang/rust

ice: `Field projection applied to a type other than Adt or Tuple` with `-Wrust-2021-incompatible-closure-captures`

Opened this issue · 2 comments

snippet:

struct V(&mut i32);

fn nested(v: &V) {
    || {
        V(_somename) = v;
        v.0 = 0;
    };
}

Version information

rustc 1.77.0-nightly (f4d794ea0 2023-12-28)
binary: rustc
commit-hash: f4d794ea0b845413344621d89f6c945062748485
commit-date: 2023-12-28
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

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

Program output

error[E0106]: missing lifetime specifier
 --> /tmp/icemaker_global_tempdir.dEdA4AEPEHqR/rustc_testrunner_tmpdir_reporting.G0gtnm9XDA0t/mvce.rs:1:10
  |
1 | struct V(&mut i32);
  |          ^ expected named lifetime parameter
  |
help: consider introducing a named lifetime parameter
  |
1 | struct V<'a>(&'a mut i32);
  |         ++++  ++

error[E0425]: cannot find value `_somename` in this scope
 --> /tmp/icemaker_global_tempdir.dEdA4AEPEHqR/rustc_testrunner_tmpdir_reporting.G0gtnm9XDA0t/mvce.rs:5:11
  |
5 |         V(_somename) = v;
  |           ^^^^^^^^^ not found in this scope

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

error[E0308]: mismatched types
 --> /tmp/icemaker_global_tempdir.dEdA4AEPEHqR/rustc_testrunner_tmpdir_reporting.G0gtnm9XDA0t/mvce.rs:5:9
  |
5 |         V(_somename) = v;
  |         ^^^^^^^^^^^^   - this expression has type `&V`
  |         |
  |         expected `&V`, found `V`

error[E0308]: mismatched types
 --> /tmp/icemaker_global_tempdir.dEdA4AEPEHqR/rustc_testrunner_tmpdir_reporting.G0gtnm9XDA0t/mvce.rs:6:15
  |
6 |         v.0 = 0;
  |         ---   ^ expected `&mut i32`, found integer
  |         |
  |         expected due to the type of this binding
  |
help: consider dereferencing here to assign to the mutably borrowed value
  |
6 |         *v.0 = 0;
  |         +

error: internal compiler error: compiler/rustc_middle/src/ty/closure.rs:322:21: Field projection applied to a type other than Adt or Tuple: &ReLateParam(DefId(0:6 ~ mvce[7610]::nested), BrNamed(DefId(0:8 ~ mvce[7610]::nested::'_), '_)) V.

thread 'rustc' panicked at /rustc/f4d794ea0b845413344621d89f6c945062748485/compiler/rustc_errors/src/lib.rs:1068:30:
Box<dyn Any>
stack backtrace:
   0:     0x7f55a858b756 - std::backtrace_rs::backtrace::libunwind::trace::h3a8e5867b01d1b80
                               at /rustc/f4d794ea0b845413344621d89f6c945062748485/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f55a858b756 - std::backtrace_rs::backtrace::trace_unsynchronized::he397ef0e45adff5d
                               at /rustc/f4d794ea0b845413344621d89f6c945062748485/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f55a858b756 - std::sys_common::backtrace::_print_fmt::h25cea7a1fa724fb5
                               at /rustc/f4d794ea0b845413344621d89f6c945062748485/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f55a858b756 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hda7577428151df9d
                               at /rustc/f4d794ea0b845413344621d89f6c945062748485/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f55a85de080 - core::fmt::rt::Argument::fmt::hb2ec9e184bf02ba0
                               at /rustc/f4d794ea0b845413344621d89f6c945062748485/library/core/src/fmt/rt.rs:142:9
   5:     0x7f55a85de080 - core::fmt::write::h3465386ebc0a8978
                               at /rustc/f4d794ea0b845413344621d89f6c945062748485/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f55a857f49f - std::io::Write::write_fmt::hd97c5a975dde240c
                               at /rustc/f4d794ea0b845413344621d89f6c945062748485/library/std/src/io/mod.rs:1810:15
   7:     0x7f55a858b534 - std::sys_common::backtrace::_print::h40f73d3c1d514bff
                               at /rustc/f4d794ea0b845413344621d89f6c945062748485/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f55a858b534 - std::sys_common::backtrace::print::h52313c48a0b47ef2
                               at /rustc/f4d794ea0b845413344621d89f6c945062748485/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f55a858e2c7 - std::panicking::default_hook::{{closure}}::haa180c42e4a369b8
  10:     0x7f55a858e029 - std::panicking::default_hook::h2608c79ece8d0d38
                               at /rustc/f4d794ea0b845413344621d89f6c945062748485/library/std/src/panicking.rs:292:9
  11:     0x7f55ab354c5c - std[3786b4fe60d6306f]::panicking::update_hook::<alloc[3092222d4273bb6b]::boxed::Box<rustc_driver_impl[5c34c1e050da57aa]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f55a858ea16 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hb87a29f68be8c251
                               at /rustc/f4d794ea0b845413344621d89f6c945062748485/library/alloc/src/boxed.rs:2029:9
  13:     0x7f55a858ea16 - std::panicking::rust_panic_with_hook::h184b82fc904f3d9c
                               at /rustc/f4d794ea0b845413344621d89f6c945062748485/library/std/src/panicking.rs:783:13
  14:     0x7f55ab38dd94 - std[3786b4fe60d6306f]::panicking::begin_panic::<rustc_errors[33e8040be929cdf9]::ExplicitBug>::{closure#0}
  15:     0x7f55ab38a196 - std[3786b4fe60d6306f]::sys_common::backtrace::__rust_end_short_backtrace::<std[3786b4fe60d6306f]::panicking::begin_panic<rustc_errors[33e8040be929cdf9]::ExplicitBug>::{closure#0}, !>
  16:     0x7f55ab385436 - std[3786b4fe60d6306f]::panicking::begin_panic::<rustc_errors[33e8040be929cdf9]::ExplicitBug>
  17:     0x7f55ab398c91 - <rustc_errors[33e8040be929cdf9]::diagnostic_builder::BugAbort as rustc_errors[33e8040be929cdf9]::diagnostic_builder::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7f55ab76ebee - <rustc_errors[33e8040be929cdf9]::DiagCtxt>::bug::<alloc[3092222d4273bb6b]::string::String>
  19:     0x7f55ab80a2db - rustc_middle[f757abec48a5eb78]::util::bug::opt_span_bug_fmt::<rustc_span[65f71dc0888967d4]::span_encoding::Span>::{closure#0}
  20:     0x7f55ab7f3cda - rustc_middle[f757abec48a5eb78]::ty::context::tls::with_opt::<rustc_middle[f757abec48a5eb78]::util::bug::opt_span_bug_fmt<rustc_span[65f71dc0888967d4]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f55ab7f3b58 - rustc_middle[f757abec48a5eb78]::ty::context::tls::with_context_opt::<rustc_middle[f757abec48a5eb78]::ty::context::tls::with_opt<rustc_middle[f757abec48a5eb78]::util::bug::opt_span_bug_fmt<rustc_span[65f71dc0888967d4]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f55a978cfd0 - rustc_middle[f757abec48a5eb78]::util::bug::bug_fmt
  23:     0x7f55ab7f1ca9 - rustc_middle[f757abec48a5eb78]::ty::closure::place_to_string_for_capture
  24:     0x7f55ab576c58 - <rustc_hir_typeck[1e5186ab7a582f5e]::fn_ctxt::FnCtxt>::compute_2229_migrations
  25:     0x7f55acfe0a2b - <rustc_hir_typeck[1e5186ab7a582f5e]::fn_ctxt::FnCtxt>::analyze_closure
  26:     0x7f55a947ab62 - <rustc_hir_typeck[1e5186ab7a582f5e]::upvar::InferBorrowKindVisitor as rustc_hir[5d4f640d92b3143d]::intravisit::Visitor>::visit_expr
  27:     0x7f55ac899f84 - <rustc_hir_typeck[1e5186ab7a582f5e]::upvar::InferBorrowKindVisitor as rustc_hir[5d4f640d92b3143d]::intravisit::Visitor>::visit_block
  28:     0x7f55ac8fdc34 - rustc_hir_typeck[1e5186ab7a582f5e]::typeck
  29:     0x7f55ac8fcc33 - rustc_query_impl[6f15f6c85c1a873b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6f15f6c85c1a873b]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f757abec48a5eb78]::query::erase::Erased<[u8; 8usize]>>
  30:     0x7f55ac816f03 - rustc_query_system[7fd09d8d21d1b510]::query::plumbing::try_execute_query::<rustc_query_impl[6f15f6c85c1a873b]::DynamicConfig<rustc_query_system[7fd09d8d21d1b510]::query::caches::VecCache<rustc_span[65f71dc0888967d4]::def_id::LocalDefId, rustc_middle[f757abec48a5eb78]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[6f15f6c85c1a873b]::plumbing::QueryCtxt, false>
  31:     0x7f55ac816b90 - rustc_query_impl[6f15f6c85c1a873b]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7f55acc4b86f - <rustc_middle[f757abec48a5eb78]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[9c2d6d0d7a0bf722]::check_crate::{closure#7}>::{closure#0}
  33:     0x7f55acc4a065 - rustc_hir_analysis[9c2d6d0d7a0bf722]::check_crate
  34:     0x7f55acef3369 - rustc_interface[6675b02aac4159d5]::passes::analysis
  35:     0x7f55acef2f9d - rustc_query_impl[6f15f6c85c1a873b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6f15f6c85c1a873b]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f757abec48a5eb78]::query::erase::Erased<[u8; 1usize]>>
  36:     0x7f55ad5ac764 - rustc_query_system[7fd09d8d21d1b510]::query::plumbing::try_execute_query::<rustc_query_impl[6f15f6c85c1a873b]::DynamicConfig<rustc_query_system[7fd09d8d21d1b510]::query::caches::SingleCache<rustc_middle[f757abec48a5eb78]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[6f15f6c85c1a873b]::plumbing::QueryCtxt, false>
  37:     0x7f55ad5ac555 - rustc_query_impl[6f15f6c85c1a873b]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  38:     0x7f55ad637992 - rustc_interface[6675b02aac4159d5]::interface::run_compiler::<core[d43ed1021aff63f4]::result::Result<(), rustc_span[65f71dc0888967d4]::ErrorGuaranteed>, rustc_driver_impl[5c34c1e050da57aa]::run_compiler::{closure#0}>::{closure#0}
  39:     0x7f55ad5bb486 - std[3786b4fe60d6306f]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[6675b02aac4159d5]::util::run_in_thread_with_globals<rustc_interface[6675b02aac4159d5]::util::run_in_thread_pool_with_globals<rustc_interface[6675b02aac4159d5]::interface::run_compiler<core[d43ed1021aff63f4]::result::Result<(), rustc_span[65f71dc0888967d4]::ErrorGuaranteed>, rustc_driver_impl[5c34c1e050da57aa]::run_compiler::{closure#0}>::{closure#0}, core[d43ed1021aff63f4]::result::Result<(), rustc_span[65f71dc0888967d4]::ErrorGuaranteed>>::{closure#0}, core[d43ed1021aff63f4]::result::Result<(), rustc_span[65f71dc0888967d4]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d43ed1021aff63f4]::result::Result<(), rustc_span[65f71dc0888967d4]::ErrorGuaranteed>>
  40:     0x7f55ad5bb2b3 - <<std[3786b4fe60d6306f]::thread::Builder>::spawn_unchecked_<rustc_interface[6675b02aac4159d5]::util::run_in_thread_with_globals<rustc_interface[6675b02aac4159d5]::util::run_in_thread_pool_with_globals<rustc_interface[6675b02aac4159d5]::interface::run_compiler<core[d43ed1021aff63f4]::result::Result<(), rustc_span[65f71dc0888967d4]::ErrorGuaranteed>, rustc_driver_impl[5c34c1e050da57aa]::run_compiler::{closure#0}>::{closure#0}, core[d43ed1021aff63f4]::result::Result<(), rustc_span[65f71dc0888967d4]::ErrorGuaranteed>>::{closure#0}, core[d43ed1021aff63f4]::result::Result<(), rustc_span[65f71dc0888967d4]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d43ed1021aff63f4]::result::Result<(), rustc_span[65f71dc0888967d4]::ErrorGuaranteed>>::{closure#1} as core[d43ed1021aff63f4]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41:     0x7f55a8598945 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h060b15507a6e395e
                               at /rustc/f4d794ea0b845413344621d89f6c945062748485/library/alloc/src/boxed.rs:2015:9
  42:     0x7f55a8598945 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6e5319cc8a1e4225
                               at /rustc/f4d794ea0b845413344621d89f6c945062748485/library/alloc/src/boxed.rs:2015:9
  43:     0x7f55a8598945 - std::sys::unix::thread::Thread::new::thread_start::h8fbbd825c116e901
                               at /rustc/f4d794ea0b845413344621d89f6c945062748485/library/std/src/sys/unix/thread.rs:108:17
  44:     0x7f55a83849eb - <unknown>
  45:     0x7f55a84087cc - <unknown>
  46:                0x0 - <unknown>

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.77.0-nightly (f4d794ea0 2023-12-28) running on x86_64-unknown-linux-gnu

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

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

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

Regression (from error) in nightly-2022-11-06

found 9 bors merge commits in the specified range

  • commit[0] 2022-11-04: Auto merge of #103978 - matthiaskrgr:rollup-iym9kmg, r=matthiaskrgr
  • commit[1] 2022-11-04: Auto merge of #103298 - ferrocene:pa-compile-flags-last, r=jyn514
  • commit[2] 2022-11-05: Auto merge of #103991 - matthiaskrgr:rollup-tj53nte, r=matthiaskrgr
  • commit[3] 2022-11-05: Auto merge of #103992 - weihanglo:update-cargo, r=weihanglo
  • commit[4] 2022-11-05: Auto merge of #103998 - Dylan-DPC:rollup-2nbmtc9, r=Dylan-DPC
  • commit[5] 2022-11-05: Auto merge of #103691 - michaelwoerister:consistent-slice-and-str-cpp-like-debuginfo-names, r=wesleywiser
  • commit[6] 2022-11-05: Auto merge of #103831 - chenyukang:yukang/fix-103751-ice, r=nagisa
  • commit[7] 2022-11-05: Auto merge of #104017 - matthiaskrgr:rollup-k8i0j9m, r=matthiaskrgr
  • commit[8] 2022-11-05: Auto merge of #102458 - JohnTitor:stabilize-instruction-set, r=oli-obk

@rustbot label regression-from-stable-to-stable


Strangely, I can't get this to reproduce on beta or nightly locally or on the playground, but it does reproduce on beta/nighly Godbolt and on stable everywhere.

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium