Skip to content

Destructuring assingment in closure causes "broken MIR in DefId [...] can't project out of PlaceTy [...]" #96299

Closed
@maltekliemann

Description

@maltekliemann

Code

enum E {
    S(u8),
}

fn main() {
    let x = E::S(0);
    || {
        let E::S(_x) = x;
    };
}

Notes:

  • Replacing _x with _ fixes the problem
  • Removing the closure fixes the problem

Meta

rustc --version --verbose:

rustc 1.62.0-nightly (52ca603da 2022-04-12)
binary: rustc
commit-hash: 52ca603da73ae9eaddf96f77953b33ad8c47cc8e
commit-date: 2022-04-12
host: x86_64-apple-darwin
release: 1.62.0-nightly
LLVM version: 14.0.0

Error output

~/tmp/rust-ice $ cargo build
   Compiling rust-ice v0.0.0 (/Users/malte/tmp/rust-ice)
warning: unused closure that must be used
 --> src/main.rs:7:5
  |
7 | /     || {
8 | |         let E::S(_x) = x;
9 | |     };
  | |______^
  |
  = note: `#[warn(unused_must_use)]` on by default
  = note: closures are lazy and do nothing unless called

warning: Error finalizing incremental compilation session directory `/Users/malte/tmp/rust-ice/target/debug/incremental/rust_ice-y91kwbgiinrt/s-g92x6q1o4k-6235wp-working`: No such file or directory (os error 2)

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: broken MIR in DefId(0:8 ~ rust_ice[3e90]::main::{closure#0}) (((*((*_1).0: &u8)).0: u8)): can't project out of PlaceTy { ty: u8, variant_index: None }
 --> src/main.rs:8:18
  |
8 |         let E::S(_x) = x;
  |                  ^^
  |
  = note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:860:31

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:795:20

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at /rustc/4ca19e09d302a4cbde14f9cb1bc109179dc824cd/compiler/rustc_middle/src/ty/relate.rs:419:59

error: internal compiler error: broken MIR in DefId(0:7 ~ rust_ice[3e90]::main) ((_1.0: u8)): can't project out of PlaceTy { ty: E, variant_index: None }
 --> src/main.rs:7:5
  |
7 | /     || {
8 | |         let E::S(_x) = x;
9 | |     };
  | |_____^
  |
  = note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:860:31

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1346:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: 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.62.0-nightly (4ca19e09d 2022-04-19) running on x86_64-apple-darwin

note: compiler flags: --crate-type bin -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
warning: `rust-ice` (bin "rust-ice") generated 2 warnings
error: could not compile `rust-ice`; 2 warnings emitted
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1346:13
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
   3: core::ptr::drop_in_place::<rustc_session::parse::ParseSess>
   4: <alloc::rc::Rc<rustc_session::session::Session> as core::ops::drop::Drop>::drop
   5: core::ptr::drop_in_place::<rustc_interface::interface::Compiler>
   6: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
   7: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>
   8: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions