rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.97k stars 12.68k forks source link

Compiler unexpectedly panicked - async #127874

Closed soltybeans closed 3 months ago

soltybeans commented 3 months ago

Haven't seen this before :) I'm learning/messing with some async stuff using the following crates:

async-trait = "0.1.81"
serde_json = "1.0.120"
serde = { version = "1.0.204", features = ["derive"] }
crossbeam-channel = "0.5.13"
crossbeam-utils = "0.8.20"

I am pretty sure my code shouldn't work, but the snippet I changed brought up a compiler panic error. Please close if this is not the right place. Just following the cargo check output.


Code

pub(crate) fn main() -> Result<()> {
    Runtime::init(try_main())
}

async fn try_main() -> Result<()> {
    let (sender, receiver) = bounded(1);
    let handler = Arc::new(Handler{sender});
    let mut seen_messages = SeenMessages{seen: HashSet::new()};
    let _ = thread::spawn(async move || {
        Runtime::new().with_handler(handler).run().await?;
        loop {
            let msg = receiver.recv_timeout(Duration::from_millis(1000)).expect("Cannot read message!");
            seen_messages.seen.insert(msg);
        }
    });
    Ok(())
}

Meta

rustc --version --verbose:

rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-unknown-linux-gnu
release: 1.79.0
LLVM version: 18.1.7

Error output

thread 'rustc' panicked at compiler/rustc_mir_transform/src/coroutine/by_move_body.rs:140:21:
assertion `left != right` failed: `FnOnce` coroutine-closures return coroutines that capture from their body; it will always result in a borrowck error!
  left: FnOnce
 right: FnOnce
stack backtrace:
   0: rust_begin_unwind
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:652:5
   1: core::panicking::panic_fmt
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:72:14
   2: core::panicking::assert_failed_inner
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:404:23
   3: core::panicking::assert_failed::<rustc_type_ir::ClosureKind, rustc_type_ir::ClosureKind>
   4: <rustc_mir_transform::coroutine::by_move_body::ByMoveBody as rustc_middle::mir::MirPass>::run_pass
   5: rustc_mir_transform::pass_manager::run_passes_inner
      [... omitted 1 frame ...]
   6: rustc_mir_transform::ffi_unwind_calls::has_ffi_unwind_calls
      [... omitted 1 frame ...]
   7: rustc_mir_transform::mir_promoted
      [... omitted 1 frame ...]
   8: rustc_borrowck::mir_borrowck
      [... omitted 1 frame ...]
   9: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  10: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: the compiler unexpectedly panicked. this is a bug.
Backtrace

``` ```

matthiaskrgr commented 3 months ago

Does it also happen with latest nightly?

compiler-errors commented 3 months ago

Yeah this should be fixed on nightly.

compiler-errors commented 3 months ago

That is to say, that's my suspicion. Please double check it. If not, I'll look into this.

soltybeans commented 3 months ago

Yes :) thanks! Nightly today works. Confirmed with

 rustc 1.81.0-nightly (032be6f7b 2024-07-16)

cargo check fails successfully :)

Thanks!