Skip to content

Cannot create local mono-item #48751

Closed
Closed
@alecmocatta

Description

@alecmocatta

I'm getting the following ICE on at least various nightlies going back a month.

error: internal compiler error: librustc_mir/monomorphize/collector.rs:747: Cannot create local mono-item for DefId(18/0:171 ~ my_lib_crate[8418]::my_lib_submod[0]::{{impl}}[18]::new[0])

thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:535:9
stack backtrace:
   0:     0x7f1f4999ee83 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h06394d49c249a4bb
                               at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1:     0x7f1f49995d64 - std::sys_common::backtrace::_print::h9b103b13339f9058
                               at libstd/sys_common/backtrace.rs:71
   2:     0x7f1f4999b72d - std::panicking::default_hook::{{closure}}::h098a999e0c1b279e
                               at libstd/sys_common/backtrace.rs:59
                               at libstd/panicking.rs:207
   3:     0x7f1f4999b429 - std::panicking::default_hook::hd2f541195ebc1dea
                               at libstd/panicking.rs:223
   4:     0x7f1f463f725d - core::ops::function::Fn::call::h0946a0c3275debde
   5:     0x7f1f4999bbc9 - std::panicking::rust_panic_with_hook::h127f3d328cb9c946
                               at libstd/panicking.rs:403
   6:     0x7f1f4551069a - std::panicking::begin_panic::hbfebf35e964b9da1
   7:     0x7f1f45534ce5 - rustc_errors::Handler::bug::hf13b4cd4ede3ee59
   8:     0x7f1f466f01bf - rustc::session::opt_span_bug_fmt::{{closure}}::hfee030be9b8ff1e8
   9:     0x7f1f467a9ef5 - rustc::ty::context::tls::with_opt::{{closure}}::h88a2cfeee7591ffa
  10:     0x7f1f463ef78f - <std::thread::local::LocalKey<T>>::try_with::h8e6e81c50519f79b
  11:     0x7f1f463ef3c6 - <std::thread::local::LocalKey<T>>::with::h3efd74c0542fa548
  12:     0x7f1f467a9cf6 - rustc::ty::context::tls::with::h4e7056c46f6be47e
  13:     0x7f1f467a9ea7 - rustc::ty::context::tls::with_opt::hcf162eb7c7be45bb
  14:     0x7f1f466f00c4 - rustc::session::opt_span_bug_fmt::h275dfefeda53d72f
  15:     0x7f1f466f0036 - rustc::session::bug_fmt::he81ec97ba9fd393d
  16:     0x7f1f473ccd02 - rustc_mir::monomorphize::collector::should_monomorphize_locally::hadc53c23cf2ecd35
  17:     0x7f1f473ccad4 - rustc_mir::monomorphize::collector::visit_instance_use::h2eba081f4558be70
  18:     0x7f1f473cca9e - rustc_mir::monomorphize::collector::visit_fn_use::he4b23b23a4337853
  19:     0x7f1f473cc5ac - <rustc_mir::monomorphize::collector::MirNeighborCollector<'a, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_terminator_kind::hddb5a5bfa62a6bdc
  20:     0x7f1f47230909 - rustc::mir::visit::Visitor::visit_mir::h557b1066eb9ca420
  21:     0x7f1f473c94d2 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  22:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  23:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  24:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  25:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  26:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  27:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  28:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  29:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  30:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  31:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  32:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  33:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  34:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  35:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  36:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  37:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  38:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  39:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  40:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  41:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  42:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  43:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  44:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  45:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  46:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  47:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  48:     0x7f1f473c8d62 - rustc_mir::monomorphize::collector::collect_crate_mono_items::h7d3fa603ca193ea1
  49:     0x7f1f3eef6391 - rustc_trans::base::collect_and_partition_translation_items::hbc56d9acdbfb8fce
  50:     0x7f1f46591055 - rustc::dep_graph::graph::DepGraph::with_task_impl::haab752cf4b04a9d9
  51:     0x7f1f469468c1 - rustc::ty::maps::<impl rustc::ty::maps::queries::collect_and_partition_translation_items<'tcx>>::force::h173e27a678062fc0
  52:     0x7f1f46947434 - rustc::ty::maps::<impl rustc::ty::maps::queries::collect_and_partition_translation_items<'tcx>>::try_get::h8458681d3977b430
  53:     0x7f1f469743c5 - rustc::ty::maps::TyCtxtAt::collect_and_partition_translation_items::h7e54fb221877b03e
  54:     0x7f1f4696d45e - rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::collect_and_partition_translation_items::h0fe8a60b44cc74e1
  55:     0x7f1f3eef1d5b - rustc_trans::base::trans_crate::h95abd4e4789925dc
  56:     0x7f1f3ef4f497 - <rustc_trans::LlvmTransCrate as rustc_trans_utils::trans_crate::TransCrate>::trans_crate::h4fb823522ed0f41d
  57:     0x7f1f49d5eaa2 - rustc_driver::driver::phase_4_translate_to_llvm::h040f62e78a90a498
  58:     0x7f1f49d57a2e - rustc_driver::driver::compile_input::{{closure}}::he9c5443356997304
  59:     0x7f1f49ce44b4 - rustc::ty::context::TyCtxt::create_and_enter::h010c9fa8ed1d20fc
  60:     0x7f1f49d55a5e - rustc_driver::driver::compile_input::hd0a77987b3f07ae0
  61:     0x7f1f49d7244a - rustc_driver::run_compiler::h7e92d64f306a4def
  62:     0x7f1f49c9d9f0 - std::sys_common::backtrace::__rust_begin_short_backtrace::hcea77d6abfa0c596
  63:     0x7f1f499b4a6e - __rust_maybe_catch_panic
                               at libpanic_unwind/lib.rs:102
  64:     0x7f1f49cd6db6 - <F as alloc::boxed::FnBox<A>>::call_box::h45c47cff726094f9
  65:     0x7f1f499abd1b - std::sys::unix::thread::Thread::new::thread_start::h2ff3c08e553ac72c
                               at /checkout/src/liballoc/boxed.rs:793
                               at libstd/sys_common/thread.rs:24
                               at libstd/sys/unix/thread.rs:90
  66:     0x7f1f4486f7fb - start_thread
  67:     0x7f1f49660b5e - clone
  68:                0x0 - <unknown>

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.26.0-nightly (259e4a678 2018-03-04) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -C target-cpu=native

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

I've tried to get a smaller repro but as yet haven't been successful. Below is some code to give an idea of what's going on in case it's useful, but as mentioned something's missing as it doesn't repro.

use std::{thread};
use std::sync::Arc;
use std::convert::AsRef;

#[derive(Debug)]
struct A(usize);
impl A {
    fn hello(&self) {
        println!("hello {}", self.0);
    }
    // fn run(abc: Arc<Self>) -> thread::JoinHandle<()> { // works fine
    fn run<X:AsRef<Self>+Send+'static>(abc: X) -> thread::JoinHandle<()> { // ICE
        abc.as_ref().hello();
        thread::spawn(move||{
            let abc = abc;
            let abc: &A = abc.as_ref();
            abc.hello();
        })
    }
}

And in another crate (if same crate then it works fine):

use std::sync::Arc;
fn main() {
    let abc = A(123);
    A::run(Arc::new(abc)).join().unwrap();
}

Also if I replace Arc with borrow::Borrow, it works fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-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