Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler error when an async function is store in a async struct #98634

Closed
jfortin42 opened this issue Jun 28, 2022 · 5 comments · Fixed by #103342
Closed

Compiler error when an async function is store in a async struct #98634

jfortin42 opened this issue Jun 28, 2022 · 5 comments · Fixed by #103342
Assignees
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jfortin42
Copy link

jfortin42 commented Jun 28, 2022

Hello,

I was trying differents things with Future and callbacks - to be more precise, I am trying to store an asynchronous callback inside an asynchronous struct.
In my attempts, I found an unexpected compiler crash - I have taken the care to create a minimal reproducible example, which you can see, and test for yourself - note that the crash occurs both on the latest "stable" and "nightly" versions:

Code

use std::{
    future::Future,
    pin::Pin,
    task::{Context, Poll},
};

pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> {
    pub callback: F,
}

impl<F> Future for StructAsync<F>
where
    F: Fn() -> Pin<Box<dyn Future<Output = ()>>>,
{
    type Output = ();

    fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
        Poll::Pending
    }
}

async fn callback() {}

#[tokio::main]
async fn main() {
    StructAsync { callback }.await;
}

Meta

rustc --version --verbose:

rustc 1.61.0 (fe5b13d68 2022-05-18)
binary: rustc
commit-hash: fe5b13d681f25ee6474be29d748c65adcd91f69e
commit-date: 2022-05-18
host: x86_64-apple-darwin
release: 1.61.0
LLVM version: 14.0.0

Error output

warning: Error finalizing incremental compilation session directory `/Users/jonathan/Documents/rust/compiler_error/target/debug/incremental/compiler_error-236kbd4gmvetj/s-gb5nhhpzbs-1n5kt82-working`: No such file or directory (os error 2)

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: Encountered errors `[FulfillmentError(Obligation(predicate=Binder(ProjectionPredicate(ProjectionTy { substs: [fn() -> impl std::future::Future<Output = ()> {callback}, ()], item_def_id: DefId(2:3311 ~ core[5293]::ops::function::FnOnce::Output) }, Ty(std::pin::Pin<std::boxed::Box<(dyn std::future::Future<Output = ()> + 'static)>>)), []), depth=2),MismatchedProjectionTypes(Sorts(ExpectedFound { expected: std::future::from_generator::GenFuture<[static generator@src/main.rs:22:21: 22:23]>, found: std::pin::Pin<std::boxed::Box<(dyn std::future::Future<Output = ()> + 'static)>> })))]` resolving bounds outside of type inference
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/codegen.rs:125:24

error: internal compiler error: Encountered errors `[FulfillmentError(Obligation(predicate=Binder(ProjectionPredicate(ProjectionTy { substs: [fn() -> impl std::future::Future<Output = ()> {callback}, ()], item_def_id: DefId(2:3311 ~ core[5293]::ops::function::FnOnce::Output) }, Ty(std::pin::Pin<std::boxed::Box<(dyn std::future::Future<Output = ()> + 'static)>>)), []), depth=1),MismatchedProjectionTypes(Sorts(ExpectedFound { expected: std::future::from_generator::GenFuture<[static generator@src/main.rs:22:21: 22:23]>, found: std::pin::Pin<std::boxed::Box<(dyn std::future::Future<Output = ()> + 'static)>> })))]` resolving bounds outside of type inference
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/codegen.rs:125:24

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1309:13
Backtrace

stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
   3: core::ptr::drop_in_place::<rustc_session::parse::ParseSess>
   4: <alloc::rc::Rc<rustc_session::session::Session> as core::ops::drop::Drop>::drop
   5: core::ptr::drop_in_place::<rustc_interface::interface::Compiler>
   6: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
   7: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>
   8: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>

On nightly

Meta

rustc +nightly --version --verbose:

rustc 1.64.0-nightly (2f3ddd9f5 2022-06-27)
binary: rustc
commit-hash: 2f3ddd9f594adf9773547aa7cedb43c4ac8ffd2f
commit-date: 2022-06-27
host: x86_64-apple-darwin
release: 1.64.0-nightly
LLVM version: 14.0.6

Error output

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_monomorphize/src/collector.rs:958:93
Backtrace

stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: <rustc_monomorphize::collector::MirNeighborCollector as rustc_middle::mir::visit::Visitor>::visit_terminator
   4: rustc_monomorphize::collector::collect_neighbours
   5: rustc_monomorphize::collector::collect_items_rec
   6: rustc_monomorphize::collector::collect_items_rec
   7: rustc_monomorphize::collector::collect_items_rec
   8: rustc_monomorphize::collector::collect_items_rec
   9: rustc_monomorphize::collector::collect_items_rec
  10: rustc_monomorphize::collector::collect_items_rec
  11: rustc_monomorphize::collector::collect_items_rec
  12: rustc_monomorphize::collector::collect_items_rec
  13: rustc_monomorphize::collector::collect_items_rec
  14: rustc_monomorphize::collector::collect_items_rec
  15: rustc_monomorphize::collector::collect_items_rec
  16: rustc_monomorphize::collector::collect_items_rec
  17: rustc_monomorphize::collector::collect_items_rec
  18: <rustc_session::session::Session>::time::<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}>
  19: rustc_monomorphize::collector::collect_crate_mono_items
  20: rustc_monomorphize::partitioning::collect_and_partition_mono_items
  21: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), (&std::collections::hash::set::HashSet<rustc_span::def_id::DefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, &[rustc_middle::mir::mono::CodegenUnit])>
  22: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), (&std::collections::hash::set::HashSet<rustc_span::def_id::DefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, &[rustc_middle::mir::mono::CodegenUnit])>>
  23: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::collect_and_partition_mono_items, rustc_query_impl::plumbing::QueryCtxt>
  24: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::collect_and_partition_mono_items
  25: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  26: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
  27: <rustc_interface::passes::QueryContext>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core::result::Result<alloc::boxed::Box<dyn core::any::Any>, rustc_errors::ErrorGuaranteed>>
  28: <rustc_interface::queries::Queries>::ongoing_codegen
  29: <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::ErrorGuaranteed>>
  30: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  31: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>

@jfortin42 jfortin42 added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 28, 2022
@Rageking8
Copy link
Contributor

Rageking8 commented Jun 28, 2022

Just to add this also ICEs on current latest beta version: 1.62.0-beta.7 (2022-06-26 747075d)

@eggyal
Copy link
Contributor

eggyal commented Jun 28, 2022

And to further add, it does not ICE on stable.

@rustbot label: +regression-from-stable-to-beta

@rustbot rustbot added regression-from-stable-to-beta Performance or correctness regression from stable to beta. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jun 28, 2022
@eggyal
Copy link
Contributor

eggyal commented Jun 28, 2022

Apologies, as mentioned in the OP it does ICE on stable too (but, at least on the Playground, only when running not just building; same as for other channels).

@rustbot label: -I-prioritize -regression-from-stable-to-beta

@rustbot rustbot removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Jun 28, 2022
@ouz-a
Copy link
Contributor

ouz-a commented Aug 9, 2022

@cjgillot cjgillot added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Sep 5, 2022
@Rageking8
Copy link
Contributor

@rustbot claim
For the test

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Oct 28, 2022
…, r=compiler-errors

Add test for issue 98634

Fixes rust-lang#98634
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Oct 28, 2022
…, r=compiler-errors

Add test for issue 98634

Fixes rust-lang#98634
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 29, 2022
…, r=compiler-errors

Add test for issue 98634

Fixes rust-lang#98634
@bors bors closed this as completed in 67c469f Oct 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants