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

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

Closed
maltekliemann opened this issue Apr 21, 2022 · 5 comments · Fixed by #97325
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@maltekliemann
Copy link

maltekliemann commented Apr 21, 2022

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.

@maltekliemann maltekliemann 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 21, 2022
@matthiaskrgr
Copy link
Member

Is this still reproducible?

@maltekliemann
Copy link
Author

Yes, unfortunately, the problem persists with this setup:

rustc 1.62.0-nightly (18f314e70 2022-04-24)
binary: rustc
commit-hash: 18f314e7027fe7084aaab8620c624a0d7bd29e70
commit-date: 2022-04-24
host: x86_64-apple-darwin
release: 1.62.0-nightly
LLVM version: 14.0.1

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Apr 25, 2022

Ok, it looks like this is actually an incremental compilation issue which only appears with --edition=2021, very interesting 😄

rustc 96299.rs -Cincremental=incr -Zincremental-verify-ich=yes --edition=2021

EDIT: actually it only needs edition=2021 and is unrelated to incremental compilation 🙃

@matthiaskrgr matthiaskrgr added A-incr-comp Area: Incremental compilation and removed A-incr-comp Area: Incremental compilation labels Apr 25, 2022
@matthiaskrgr
Copy link
Member

Probably a duplicate of #95271
I'll
@rustbot prioritize
since this is just normal looking code that causes broken mir and is reproducible on stable 1.60, beta and nightly.

@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 25, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Apr 26, 2022
@apiraino
Copy link
Contributor

apiraino commented May 3, 2022

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels May 3, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jun 7, 2022
…-aman

Fix precise field capture of univariant enums

When constructing a MIR from a THIR field expression, introduce an
additional downcast projection before accessing a field of an enum.

When rebasing a place builder on top of a captured place, account for
the fact that a single HIR enum field projection corresponds to two MIR
projection elements: a downcast element and a field element.

Fixes rust-lang#95271.
Fixes rust-lang#96299.
Fixes rust-lang#96512.
Fixes rust-lang#97378.

r? `@nikomatsakis` `@arora-aman`
@bors bors closed this as completed in fd76e0e Jun 7, 2022
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. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority 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.

5 participants