Skip to content

thread 'rustc' panicked at 'Box<dyn Any>' #93002

Closed
@nbittich

Description

@nbittich

Code

use std::{sync::{mpsc, Arc, Mutex}, thread, time::Duration, rc::Rc};

fn main() {
    let m = Mutex::new(String::from("hello"));
    let (tx, rx) = mpsc::channel();
    let cl = tx.clone();
    let cl2 = tx.clone();
    thread::spawn(move || {
        let mut i:i32 = 0;
        let x = Arc::new(String::from("heyyy"));
        while cl
            .send(Arc::new(String::from(format!(
                "hello! {:?}",
                std::time::SystemTime::now()
            ))))
            .is_ok()
        {
            i+=1;
            cl.send(x.clone()).unwrap();
            thread::sleep(Duration::from_secs(2));
            let mut s = m.lock().unwrap();
            *s = String::from(format!("change me! {i}"));
            println!("from thread & mutex: {x:?} / {s}");
        }
    });
    thread::spawn(move || {
        while cl2.send(Arc::new(String::from(format!("here! {:?}", std::time::SystemTime::now())))).is_ok(){
            let mut x = &m.lock().unwrap();
            &*x=String::from("i changed u");
            println!("from thread 2, mutex {x}");
            thread::sleep(Duration::from_secs(1));
        }
    });

    loop {
        match rx.try_recv() {
            Ok(res) => println!("{res}"),
            Err(e) =>{
            thread::sleep(Duration::from_millis(200));
            },
        }
    }
}

Meta

rustc --version --verbose:

rustc 1.58.0 (02072b482 2022-01-11)
binary: rustc
commit-hash: 02072b482a8b5357f7fb5e5637444ae30e423c40
commit-date: 2022-01-11
host: x86_64-apple-darwin
release: 1.58.0
LLVM version: 13.0.0

Error output

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/02072b482a8b5357f7fb5e5637444ae30e423c40/compiler/rustc_errors/src/lib.rs:1115:9

Backtrace

stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::span_bug::<rustc_span::span_encoding::Span>
   3: <rustc_errors::Handler>::span_bug::<rustc_span::span_encoding::Span>
   4: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   5: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>::{closure#0}
   6: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>
   7: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   8: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
   9: <rustc_codegen_llvm::context::CodegenCx as rustc_middle::ty::layout::LayoutOfHelpers>::handle_layout_err
  10: <rustc_codegen_llvm::context::CodegenCx as rustc_middle::ty::layout::LayoutOf>::spanned_layout_of::{closure#0}
  11: <rustc_codegen_llvm::context::CodegenCx as rustc_middle::ty::layout::LayoutOf>::spanned_layout_of
  12: <core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::mir::LocalDecl>, rustc_codegen_ssa::mir::analyze::non_ssa_locals<rustc_codegen_llvm::builder::Builder>::{closure#0}> as core::iter::traits::iterator::Iterator>::fold::<(), core::iter::traits::iterator::Iterator::for_each::call<rustc_codegen_ssa::mir::analyze::LocalKind, <alloc::vec::Vec<rustc_codegen_ssa::mir::analyze::LocalKind> as alloc::vec::spec_extend::SpecExtend<rustc_codegen_ssa::mir::analyze::LocalKind, core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::mir::LocalDecl>, rustc_codegen_ssa::mir::analyze::non_ssa_locals<rustc_codegen_llvm::builder::Builder>::{closure#0}>>>::spec_extend::{closure#0}>::{closure#0}>
  13: rustc_codegen_ssa::mir::analyze::non_ssa_locals::<rustc_codegen_llvm::builder::Builder>
  14: rustc_codegen_ssa::mir::codegen_mir::<rustc_codegen_llvm::builder::Builder>
  15: rustc_codegen_ssa::base::codegen_instance::<rustc_codegen_llvm::builder::Builder>
  16: <rustc_middle::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define::<rustc_codegen_llvm::builder::Builder>
  17: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  18: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::symbol::Symbol, rustc_codegen_ssa::ModuleCodegen<rustc_codegen_llvm::ModuleLlvm>>
  19: rustc_codegen_llvm::base::compile_codegen_unit
  20: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
  21: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  22: <rustc_interface::queries::Queries>::ongoing_codegen
  23: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
  24: 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}>
  25: <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.

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

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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions