Skip to content

[ICE]: Broken MIR: generator contains type [&std::option::Option<StructB>] in MIR, but typeck only knows about {ResumeTy, StructB, Option<StructB>, &StructB, impl Future<Output = StructA>, ()} and [] #107414

Closed
@matthiaskrgr

Description

@matthiaskrgr

Code

fn main() {}

struct StructA {}
struct StructB {}

impl StructA {
    fn fn_taking_struct_b(&self, struct_b: &StructB) -> bool {
        true
    }
}

async fn get_struct_a_async() -> StructA {
    StructA {}
}

async fn ice() {
    match Some(StructB {}) {
        Some(struct_b) if get_struct_a_async().await.fn_taking_struct_b(&struct_b) => {}
        _ => {}
    }
}

Affected release channels

  • Previous Stable
  • Current Stable
  • Current Beta
  • Current Nightly

Rust Version

works with rustc 1.69.0-nightly (ef982929c 2023-01-27)
but crashes with rustc 1.69.0-nightly (d8da51366 2023-01-28)

Current error output

warning: unused variable: `struct_b`
 --> <anon>:8:34
  |
8 |     fn fn_taking_struct_b(&self, struct_b: &StructB) -> bool {
  |                                  ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_struct_b`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: struct `StructA` is never constructed
 --> <anon>:4:8
  |
4 | struct StructA {}
  |        ^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: struct `StructB` is never constructed
 --> <anon>:5:8
  |
5 | struct StructB {}
  |        ^^^^^^^

warning: function `get_struct_a_async` is never used
  --> <anon>:13:10
   |
13 | async fn get_struct_a_async() -> StructA {
   |          ^^^^^^^^^^^^^^^^^^

warning: function `ice` is never used
  --> <anon>:17:10
   |
17 | async fn ice() {
   |          ^^^

warning: associated function `fn_taking_struct_b` is never used
 --> <anon>:8:8
  |
8 |     fn fn_taking_struct_b(&self, struct_b: &StructB) -> bool {
  |        ^^^^^^^^^^^^^^^^^^

Backtrace

error: internal compiler error: compiler/rustc_mir_transform/src/generator.rs:895:9: Broken MIR: generator contains type [&std::option::Option<StructB>] in MIR, but typeck only knows about {ResumeTy, StructB, Option<StructB>, &StructB, impl Future<Output = StructA>, ()} and []
  --> <anon>:17:16
   |
17 |   async fn ice() {
   |  ________________^
18 | |     match Some(StructB {}) {
19 | |         Some(struct_b) if get_struct_a_async().await.fn_taking_struct_b(&struct_b) => {}
20 | |         _ => {}
21 | |     }
22 | | }
   | |_^

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/d8da51366817317d19be9bd138943eafb30bc987/compiler/rustc_errors/src/lib.rs:988:33
stack backtrace:
   0:     0x7f465316636a - std::backtrace_rs::backtrace::libunwind::trace::had87d46fba971637
                               at /rustc/d8da51366817317d19be9bd138943eafb30bc987/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f465316636a - std::backtrace_rs::backtrace::trace_unsynchronized::h2c66f2771f100182
                               at /rustc/d8da51366817317d19be9bd138943eafb30bc987/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f465316636a - std::sys_common::backtrace::_print_fmt::h12cd910ec5cd5777
                               at /rustc/d8da51366817317d19be9bd138943eafb30bc987/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f465316636a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h9d0c74c34e2df456
                               at /rustc/d8da51366817317d19be9bd138943eafb30bc987/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f46531c852e - core::fmt::write::hcdc996644d89b059
                               at /rustc/d8da51366817317d19be9bd138943eafb30bc987/library/core/src/fmt/mod.rs:1232:17
   5:     0x7f4653156ab5 - std::io::Write::write_fmt::h3802a993d37eb495
                               at /rustc/d8da51366817317d19be9bd138943eafb30bc987/library/std/src/io/mod.rs:1682:15
   6:     0x7f4653166135 - std::sys_common::backtrace::_print::he36702b5dfae4c77
                               at /rustc/d8da51366817317d19be9bd138943eafb30bc987/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f4653166135 - std::sys_common::backtrace::print::h2c8534655bf91e2f
                               at /rustc/d8da51366817317d19be9bd138943eafb30bc987/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f4653168eff - std::panicking::default_hook::{{closure}}::he3ad362fff1dddc2
                               at /rustc/d8da51366817317d19be9bd138943eafb30bc987/library/std/src/panicking.rs:267:22
   9:     0x7f4653168c3b - std::panicking::default_hook::h3d94e27c17e39628
                               at /rustc/d8da51366817317d19be9bd138943eafb30bc987/library/std/src/panicking.rs:286:9
  10:     0x7f46564eb364 - rustc_driver[5d6f901fe8560466]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f465316973a - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h5fb37f2c40637fef
                               at /rustc/d8da51366817317d19be9bd138943eafb30bc987/library/alloc/src/boxed.rs:2002:9
  12:     0x7f465316973a - std::panicking::rust_panic_with_hook::h510712981785b9a1
                               at /rustc/d8da51366817317d19be9bd138943eafb30bc987/library/std/src/panicking.rs:692:13
  13:     0x7f4656bfd611 - std[2a564ecbf74566d5]::panicking::begin_panic::<rustc_errors[95526c6eab03dbe]::ExplicitBug>::{closure#0}
  14:     0x7f4656bfc916 - std[2a564ecbf74566d5]::sys_common::backtrace::__rust_end_short_backtrace::<std[2a564ecbf74566d5]::panicking::begin_panic<rustc_errors[95526c6eab03dbe]::ExplicitBug>::{closure#0}, !>
  15:     0x7f4656b67116 - std[2a564ecbf74566d5]::panicking::begin_panic::<rustc_errors[95526c6eab03dbe]::ExplicitBug>
  16:     0x7f4656b73716 - std[2a564ecbf74566d5]::panic::panic_any::<rustc_errors[95526c6eab03dbe]::ExplicitBug>
  17:     0x7f4656b72b92 - <rustc_errors[95526c6eab03dbe]::HandlerInner>::span_bug::<rustc_span[81d2c2324150acba]::span_encoding::Span, &alloc[f5609c137388eaf0]::string::String>
  18:     0x7f4656b72907 - <rustc_errors[95526c6eab03dbe]::Handler>::span_bug::<rustc_span[81d2c2324150acba]::span_encoding::Span, &alloc[f5609c137388eaf0]::string::String>
  19:     0x7f4656bc6b7b - rustc_middle[8f019e7c475b3106]::util::bug::opt_span_bug_fmt::<rustc_span[81d2c2324150acba]::span_encoding::Span>::{closure#0}
  20:     0x7f4656bc6bca - rustc_middle[8f019e7c475b3106]::ty::context::tls::with_opt::<rustc_middle[8f019e7c475b3106]::util::bug::opt_span_bug_fmt<rustc_span[81d2c2324150acba]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f4656bc65d6 - rustc_middle[8f019e7c475b3106]::ty::context::tls::with_context_opt::<rustc_middle[8f019e7c475b3106]::ty::context::tls::with_opt<rustc_middle[8f019e7c475b3106]::util::bug::opt_span_bug_fmt<rustc_span[81d2c2324150acba]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f4656bc5d06 - rustc_middle[8f019e7c475b3106]::util::bug::opt_span_bug_fmt::<rustc_span[81d2c2324150acba]::span_encoding::Span>
  23:     0x7f46551b3b74 - rustc_middle[8f019e7c475b3106]::util::bug::span_bug_fmt::<rustc_span[81d2c2324150acba]::span_encoding::Span>
  24:     0x7f4656ba7bb8 - rustc_mir_transform[43d5813b99755ae9]::generator::mir_generator_witnesses
  25:     0x7f4656d70245 - rustc_query_system[c44eb4bfc01a6f82]::query::plumbing::try_execute_query::<rustc_query_impl[18cfbd6e9f8daaf9]::queries::mir_generator_witnesses, rustc_query_impl[18cfbd6e9f8daaf9]::plumbing::QueryCtxt>
  26:     0x7f4656d94571 - rustc_query_system[c44eb4bfc01a6f82]::query::plumbing::get_query::<rustc_query_impl[18cfbd6e9f8daaf9]::queries::mir_generator_witnesses, rustc_query_impl[18cfbd6e9f8daaf9]::plumbing::QueryCtxt, rustc_middle[8f019e7c475b3106]::dep_graph::dep_node::DepKind>
  27:     0x7f4654fd7589 - rustc_mir_transform[43d5813b99755ae9]::mir_drops_elaborated_and_const_checked
  28:     0x7f4654fd4fd1 - rustc_query_system[c44eb4bfc01a6f82]::query::plumbing::try_execute_query::<rustc_query_impl[18cfbd6e9f8daaf9]::queries::mir_drops_elaborated_and_const_checked, rustc_query_impl[18cfbd6e9f8daaf9]::plumbing::QueryCtxt>
  29:     0x7f4654ee9165 - rustc_mir_transform[43d5813b99755ae9]::optimized_mir
  30:     0x7f4654ee7092 - rustc_query_system[c44eb4bfc01a6f82]::query::plumbing::try_execute_query::<rustc_query_impl[18cfbd6e9f8daaf9]::queries::optimized_mir, rustc_query_impl[18cfbd6e9f8daaf9]::plumbing::QueryCtxt>
  31:     0x7f4655e892ef - <rustc_query_impl[18cfbd6e9f8daaf9]::Queries as rustc_middle[8f019e7c475b3106]::ty::query::QueryEngine>::optimized_mir
  32:     0x7f4656a8544c - <rustc_middle[8f019e7c475b3106]::ty::context::TyCtxt>::generator_layout
  33:     0x7f4654f919ff - rustc_ty_utils[a0da474f4c3f9308]::layout::layout_of
  34:     0x7f4654f55b5b - rustc_query_system[c44eb4bfc01a6f82]::query::plumbing::get_query::<rustc_query_impl[18cfbd6e9f8daaf9]::queries::layout_of, rustc_query_impl[18cfbd6e9f8daaf9]::plumbing::QueryCtxt, rustc_middle[8f019e7c475b3106]::dep_graph::dep_node::DepKind>
  35:     0x7f4654f556e3 - <rustc_query_impl[18cfbd6e9f8daaf9]::Queries as rustc_middle[8f019e7c475b3106]::ty::query::QueryEngine>::layout_of
  36:     0x7f4654f91664 - rustc_ty_utils[a0da474f4c3f9308]::layout::layout_of
  37:     0x7f4654f55b5b - rustc_query_system[c44eb4bfc01a6f82]::query::plumbing::get_query::<rustc_query_impl[18cfbd6e9f8daaf9]::queries::layout_of, rustc_query_impl[18cfbd6e9f8daaf9]::plumbing::QueryCtxt, rustc_middle[8f019e7c475b3106]::dep_graph::dep_node::DepKind>
  38:     0x7f465446026e - <rustc_mir_transform[43d5813b99755ae9]::const_prop::CanConstProp>::check
  39:     0x7f4654447c45 - <rustc_mir_transform[43d5813b99755ae9]::const_prop_lint::ConstProp as rustc_mir_transform[43d5813b99755ae9]::pass_manager::MirLint>::run_lint
  40:     0x7f4654fd81ad - rustc_mir_transform[43d5813b99755ae9]::run_analysis_to_runtime_passes
  41:     0x7f4654fd6b1c - rustc_mir_transform[43d5813b99755ae9]::mir_drops_elaborated_and_const_checked
  42:     0x7f4654fd4fd1 - rustc_query_system[c44eb4bfc01a6f82]::query::plumbing::try_execute_query::<rustc_query_impl[18cfbd6e9f8daaf9]::queries::mir_drops_elaborated_and_const_checked, rustc_query_impl[18cfbd6e9f8daaf9]::plumbing::QueryCtxt>
  43:     0x7f4654ee9165 - rustc_mir_transform[43d5813b99755ae9]::optimized_mir
  44:     0x7f4654ee7092 - rustc_query_system[c44eb4bfc01a6f82]::query::plumbing::try_execute_query::<rustc_query_impl[18cfbd6e9f8daaf9]::queries::optimized_mir, rustc_query_impl[18cfbd6e9f8daaf9]::plumbing::QueryCtxt>
  45:     0x7f4654ee0dff - <rustc_middle[8f019e7c475b3106]::ty::context::TyCtxt>::instance_mir
  46:     0x7f46569b814c - rustc_middle[8f019e7c475b3106]::mir::pretty::write_mir_pretty
  47:     0x7f4656be68cd - rustc_mir_transform[43d5813b99755ae9]::dump_mir::emit_mir
  48:     0x7f46556e5f6d - rustc_interface[b1d5bb2b4f3cbcea]::passes::start_codegen
  49:     0x7f46556e3ae9 - <rustc_interface[b1d5bb2b4f3cbcea]::passes::QueryContext>::enter::<<rustc_interface[b1d5bb2b4f3cbcea]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[b34619504956bb06]::result::Result<alloc[f5609c137388eaf0]::boxed::Box<dyn core[b34619504956bb06]::any::Any>, rustc_errors[95526c6eab03dbe]::ErrorGuaranteed>>
  50:     0x7f46556df74d - <rustc_interface[b1d5bb2b4f3cbcea]::queries::Queries>::ongoing_codegen
  51:     0x7f46556de6ab - rustc_span[81d2c2324150acba]::with_source_map::<core[b34619504956bb06]::result::Result<(), rustc_errors[95526c6eab03dbe]::ErrorGuaranteed>, rustc_interface[b1d5bb2b4f3cbcea]::interface::run_compiler<core[b34619504956bb06]::result::Result<(), rustc_errors[95526c6eab03dbe]::ErrorGuaranteed>, rustc_driver[5d6f901fe8560466]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  52:     0x7f46556d7064 - <scoped_tls[15e1034a77d07a1d]::ScopedKey<rustc_span[81d2c2324150acba]::SessionGlobals>>::set::<rustc_interface[b1d5bb2b4f3cbcea]::interface::run_compiler<core[b34619504956bb06]::result::Result<(), rustc_errors[95526c6eab03dbe]::ErrorGuaranteed>, rustc_driver[5d6f901fe8560466]::run_compiler::{closure#1}>::{closure#0}, core[b34619504956bb06]::result::Result<(), rustc_errors[95526c6eab03dbe]::ErrorGuaranteed>>
  53:     0x7f46556d6762 - std[2a564ecbf74566d5]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[b1d5bb2b4f3cbcea]::util::run_in_thread_pool_with_globals<rustc_interface[b1d5bb2b4f3cbcea]::interface::run_compiler<core[b34619504956bb06]::result::Result<(), rustc_errors[95526c6eab03dbe]::ErrorGuaranteed>, rustc_driver[5d6f901fe8560466]::run_compiler::{closure#1}>::{closure#0}, core[b34619504956bb06]::result::Result<(), rustc_errors[95526c6eab03dbe]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b34619504956bb06]::result::Result<(), rustc_errors[95526c6eab03dbe]::ErrorGuaranteed>>
  54:     0x7f46556d650c - <<std[2a564ecbf74566d5]::thread::Builder>::spawn_unchecked_<rustc_interface[b1d5bb2b4f3cbcea]::util::run_in_thread_pool_with_globals<rustc_interface[b1d5bb2b4f3cbcea]::interface::run_compiler<core[b34619504956bb06]::result::Result<(), rustc_errors[95526c6eab03dbe]::ErrorGuaranteed>, rustc_driver[5d6f901fe8560466]::run_compiler::{closure#1}>::{closure#0}, core[b34619504956bb06]::result::Result<(), rustc_errors[95526c6eab03dbe]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b34619504956bb06]::result::Result<(), rustc_errors[95526c6eab03dbe]::ErrorGuaranteed>>::{closure#1} as core[b34619504956bb06]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  55:     0x7f4653173803 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h2424ddca245afa30
                               at /rustc/d8da51366817317d19be9bd138943eafb30bc987/library/alloc/src/boxed.rs:1988:9
  56:     0x7f4653173803 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hef7c0f6be4e730c6
                               at /rustc/d8da51366817317d19be9bd138943eafb30bc987/library/alloc/src/boxed.rs:1988:9
  57:     0x7f4653173803 - std::sys::unix::thread::Thread::new::thread_start::h9d9d30045441cd35
                               at /rustc/d8da51366817317d19be9bd138943eafb30bc987/library/std/src/sys/unix/thread.rs:108:17
  58:     0x7f4652f048fd - <unknown>
  59:     0x7f4652f86d20 - <unknown>
  60:                0x0 - <unknown>

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.69.0-nightly (d8da51366 2023-01-28) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_generator_witnesses] generator witness types for `ice::{closure#0}`
#1 [mir_drops_elaborated_and_const_checked] elaborating drops for `ice::{closure#0}`
#2 [optimized_mir] optimizing MIR for `ice::{closure#0}`
#3 [layout_of] computing layout of `[async fn body@<anon>:17:16: 22:2]`
#4 [layout_of] computing layout of `impl core::future::future::Future<Output = ()>`
#5 [mir_drops_elaborated_and_const_checked] elaborating drops for `ice`
#6 [optimized_mir] optimizing MIR for `ice`
end of query stack
error: aborting due to previous error; 6 warnings emitted

Anything else?

Needs rustc --emit=mir --edition 2018 <file>

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been 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.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions