Skip to content

ICE: Cannot create local mono-item within future returned as impl trait #53920

Closed as not planned
@mathall

Description

@mathall

A couple of odd requirements to trigger this one, I'm not sure how to summarize. I've boiled down the case and added comments to the code below, they all mention the circumstances which are necessary to trigger the ICE.

src/lib.rs:

extern crate futures;
extern crate tokio;

// a struct in a submodule, with a method
mod sub {
    pub struct S;

    impl S {
        pub fn meth(&self) {
        }
    }
}

// return impl trait, cannot be Box<dyn trait>
fn fun() -> impl futures::future::Future<Item=(), Error=()> {
    futures::future::lazy(|| {
        // call the method on an instance of S from within the future
        sub::S.meth();
        Ok(())
    })
}

// some trait bound parameter
pub fn run<P: AsRef<std::path::Path>>(_: P) {
    // pass the returned future to tokio
    tokio::run(fun());
}

src/main.rs:

extern crate mylib;

fn main() {
    // make a call
    mylib::run("");
}

Meta

RUST_BACKTRACE=1 cargo build:

error: internal compiler error: librustc_mir/monomorphize/collector.rs:765: Cannot create local mono-item for DefId(10/0:8 ~ mylib[784e]::sub[0]::{{impl}}[0]::meth[0])

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:554: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::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::bug_fmt
  14: rustc_mir::monomorphize::collector::should_monomorphize_locally
  15: rustc_mir::monomorphize::collector::visit_instance_use
  16: <rustc_mir::monomorphize::collector::MirNeighborCollector<'a, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_terminator_kind
  17: rustc_mir::monomorphize::collector::collect_items_rec
  18: rustc_mir::monomorphize::collector::collect_items_rec
  19: rustc_mir::monomorphize::collector::collect_items_rec
  20: rustc_mir::monomorphize::collector::collect_items_rec
  21: rustc_mir::monomorphize::collector::collect_items_rec
  22: rustc_mir::monomorphize::collector::collect_items_rec
  23: rustc_mir::monomorphize::collector::collect_items_rec
  24: rustc_mir::monomorphize::collector::collect_items_rec
  25: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}
  26: rustc_mir::monomorphize::collector::collect_crate_mono_items
  27: rustc::util::common::time
  28: rustc_codegen_llvm::base::collect_and_partition_mono_items
  29: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::collect_and_partition_mono_items<'tcx>>::compute
  30: rustc::ty::context::tls::with_context
  31: rustc::dep_graph::graph::DepGraph::with_task_impl
  32: rustc::ty::context::tls::with_related_context
  33: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  35: rustc_codegen_llvm::base::codegen_crate
  36: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  37: rustc::util::common::time
  38: rustc_driver::driver::phase_4_codegen
  39: rustc_driver::driver::compile_input::{{closure}}
  40: rustc::ty::context::tls::enter_context
  41: <std::thread::local::LocalKey<T>>::with
  42: rustc::ty::context::TyCtxt::create_and_enter
  43: rustc_driver::driver::compile_input
  44: rustc_driver::run_compiler_with_pool
  45: <scoped_tls::ScopedKey<T>>::set
  46: syntax::with_globals
  47: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  48: __rust_maybe_catch_panic
  49: rustc_driver::run
  50: rustc_driver::main
  51: std::rt::lang_start::{{closure}}
  52: std::panicking::try::do_call
  53: __rust_maybe_catch_panic
  54: std::rt::lang_start_internal
  55: main
query stack during panic:
#0 [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.28.0 (9634041f0 2018-07-30) running on x86_64-apple-darwin

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

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

error: Could not compile `mypack`.

To learn more, run the command again with --verbose.

rustc --version --verbose:

rustc 1.28.0 (9634041f0 2018-07-30)
binary: rustc
commit-hash: 9634041f0e8c0f3191d2867311276f19d0a42564
commit-date: 2018-07-30
host: x86_64-apple-darwin
release: 1.28.0
LLVM version: 6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleI-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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions