Skip to content

ICE - Broken MIR in generators #52398

Closed
Closed
@bluecookies

Description

@bluecookies

Rustc panics with the following message when trying to compile this:
error: internal compiler error: librustc_mir/transform/generator.rs:495: Broken MIR: generator contains type std::cell::Ref<u32> in MIR, but typeck only knows about for<'r, 's, 't0> {&'r std::cell::RefCell<u32>, &'s std::cell::Ref<'t0, u32>, u32, ()}

#![feature(generators, generator_trait)]
use std::ops::Generator;
use std::cell::RefCell;

fn foo<'a>(y: &'a RefCell<u32>) -> impl Generator + 'a {
    return move || {
        yield *y.borrow();
        return "Done";
    };
}

fn main() {
    let y = 10;
    let y_cell = RefCell::new(y);
    foo(&y_cell);
}

Playground link

Backtrace:

error: internal compiler error: librustc_mir/transform/generator.rs:495: Broken MIR: generator contains type std::cell::Ref<u32> in MIR, but typeck only knows about for<'r, 's, 't0> {&'r std::cell::RefCell<u32>, &'s std::cell::Ref<'t0, u32>, u32, ()}
 --> src/main.rs:6:12
  |
6 |       return move || {
  |  ____________^
7 | |         yield *y.borrow();
8 | |         return "Done";
9 | |     };
  | |_____^

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:499:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::span_bug
   8: rustc::session::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::session::opt_span_bug_fmt
  13: rustc::session::span_bug_fmt
  14: <rustc_mir::transform::generator::StateTransform as rustc_mir::transform::MirPass>::run_pass
  15: rustc_mir::transform::optimized_mir::{{closure}}
  16: rustc_mir::transform::optimized_mir
  17: rustc::ty::query::__query_compute::optimized_mir
  18: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::optimized_mir<'tcx>>::compute
  19: rustc::ty::context::tls::with_context
  20: rustc::dep_graph::graph::DepGraph::with_task_impl
  21: rustc::ty::context::tls::with_related_context
  22: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  23: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_query
  24: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::optimized_mir
  25: rustc_mir::shim::make_shim
  26: rustc::ty::query::__query_compute::mir_shims
  27: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::mir_shims<'tcx>>::compute
  28: rustc::ty::context::tls::with_context
  29: rustc::dep_graph::graph::DepGraph::with_task_impl
  30: rustc::ty::context::tls::with_related_context
  31: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  32: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  33: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::instance_mir
  34: rustc_mir::monomorphize::collector::collect_items_rec
  35: rustc_mir::monomorphize::collector::collect_items_rec
  36: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}
  37: rustc::util::common::time
  38: rustc_mir::monomorphize::collector::collect_crate_mono_items
  39: rustc::util::common::time
  40: rustc_codegen_llvm::base::collect_and_partition_mono_items
  41: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::collect_and_partition_mono_items<'tcx>>::compute
  42: rustc::ty::context::tls::with_context
  43: rustc::dep_graph::graph::DepGraph::with_task_impl
  44: rustc::ty::context::tls::with_related_context
  45: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  46: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  47: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  48: rustc::util::common::time
  49: rustc_driver::driver::phase_4_codegen
  50: rustc_driver::driver::compile_input::{{closure}}
  51: rustc::ty::context::tls::enter_context
  52: <std::thread::local::LocalKey<T>>::with
  53: rustc::ty::context::TyCtxt::create_and_enter
  54: rustc_driver::driver::compile_input
  55: rustc_driver::run_compiler_with_pool
  56: <scoped_tls::ScopedKey<T>>::set
  57: <scoped_tls::ScopedKey<T>>::set
  58: syntax::with_globals
  59: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  60: __rust_maybe_catch_panic
  61: rustc_driver::run
  62: rustc_driver::main
  63: std::rt::lang_start::{{closure}}
  64: std::panicking::try::do_call
  65: __rust_maybe_catch_panic
  66: std::rt::lang_start_internal
  67: main
query stack during panic:
#0 [optimized_mir] processing `foo::{{closure}}`
#1 [mir_shims] generating MIR shim for `std::ptr::drop_in_place`
#2 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to previous error


note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.29.0-nightly (254f8796b 2018-07-13) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

Version:

rustc 1.29.0-nightly (254f8796b 2018-07-13)
binary: rustc
commit-hash: 254f8796b729810846e2b97620032ecaf103db33
commit-date: 2018-07-13
host: x86_64-apple-darwin
release: 1.29.0-nightly
LLVM version: 7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-coroutinesArea: CoroutinesI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions