Skip to content

ICE when pattern matching an enum on a let binding within a closure, with --edition 2021 #95271

Closed
@saiintbrisson

Description

@saiintbrisson

I was messing around with the async_trait crate and an ICE was raised when I tried to pattern match an enum in the function parameter. I narrowed it down to trying to pattern match a variable that exists outside the scope from within a closure.

Code

enum Foo {
    Foo(i32),
}

fn bar(foo: Foo) {
    || {
        // `let foo = foo;` makes the ICE disappear
        let Foo::Foo(baz) = foo;
    };
}

Playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3465e1787d6792e07772f31154877280

Meta

Present in all three channels, beta, nightly and stable. Only present on 2021 edition.

rustc --version --verbose:

rustc 1.59.0 (9d1b2106e 2022-02-23)
binary: rustc
commit-hash: 9d1b2106e23b1abd32fce1f17267604a5102f57a
commit-date: 2022-02-23
host: x86_64-unknown-linux-gnu
release: 1.59.0
LLVM version: 13.0.0

Error output

error: internal compiler error: broken MIR in DefId(0:8 ~ playground[20f3]::bar::{closure#0}) (((*((*_1).0: &i32)).0: i32)): can't project out of PlaceTy { ty: i32, variant_index: None }
 --> src/lib.rs:7:22
  |
7 |         let Foo::Foo(baz) = foo;
  |                      ^^^
  |
  = note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:319:27

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

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

error: internal compiler error: broken MIR in DefId(0:7 ~ playground[20f3]::bar) ((_1.0: i32)): can't project out of PlaceTy { ty: Foo, variant_index: None }
 --> src/lib.rs:6:5
  |
6 | /     || {
7 | |         let Foo::Foo(baz) = foo;
8 | |     };
  | |_____^
  |
  = note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:319:27
Backtrace

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:1188:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: core::panicking::panic_display::<&str>
   3: <rustc_errors::HandlerInner>::flush_delayed
   4: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
   5: core::ptr::drop_in_place::<rustc_session::parse::ParseSess>
   6: <alloc::rc::Rc<rustc_session::session::Session> as core::ops::drop::Drop>::drop
   7: core::ptr::drop_in_place::<rustc_interface::interface::Compiler>
   8: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
   9: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>
  10: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
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) ❄️T-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