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

TypeError ICE with hashmap of async function pointers #107775

Closed
0xAda opened this issue Feb 7, 2023 · 4 comments · Fixed by #107779
Closed

TypeError ICE with hashmap of async function pointers #107775

0xAda opened this issue Feb 7, 2023 · 4 comments · Fixed by #107779
Assignees
Labels
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.

Comments

@0xAda
Copy link

0xAda commented Feb 7, 2023

Code

use std::collections::HashMap;
use std::future::Future;
use std::pin::Pin;
use async_trait::async_trait;

#[async_trait]
pub trait Trait {
    async fn do_something(byte: u8);
}

pub struct Struct;

#[async_trait]
impl Trait for Struct {
    async fn do_something(byte: u8) {

    }
}

pub struct Map {
    map: HashMap<u16, fn(u8) -> Pin<Box<dyn Future<Output = ()> + Send>>>,
}

impl Map {
    pub fn new() -> Self {
        let mut map = HashMap::new();
        map.insert(1, Struct::do_something);
        Self {
            map,
        }
    }
}

Meta

rustc --version --verbose:

rustc 1.69.0-nightly (e1eaa2d5d 2023-02-06)
binary: rustc
commit-hash: e1eaa2d5d4d1f5b7b89561a940718058d414e89c
commit-date: 2023-02-06
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7

Error output

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

error: internal compiler error: `TypeError` when attempting coercion but no error emitted
Backtrace

query stack during panic:
#0 [typeck] type-checking `<impl at src/lib.rs:24:1: 24:27>::new`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack
error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: `TypeError` when attempting coercion but no error emitted
  --> src/lib.rs:29:13
   |
29 |             map,
   |             ^^^
   |
   = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
              1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
              2: <rustc_hir_typeck::fn_ctxt::FnCtxt>::demand_coerce_diag
              3: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_struct_fields
              4: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
              5: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
              6: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
              7: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_expr
              8: rustc_hir_typeck::check::check_fn
              9: rustc_hir_typeck::typeck
             10: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId, &rustc_middle::ty::typeck_results::TypeckResults>
             11: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::typeck, rustc_query_impl::plumbing::QueryCtxt>
             12: rustc_data_structures::sync::par_for_each_in::<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_hir_typeck::typeck_item_bodies::{closure#0}>::{closure#0}>
             13: rustc_hir_typeck::typeck_item_bodies
             14: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), ()>
             15: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::typeck_item_bodies, rustc_query_impl::plumbing::QueryCtxt>
             16: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck_item_bodies
             17: <rustc_session::session::Session>::time::<(), rustc_hir_analysis::check_crate::{closure#7}>
             18: rustc_hir_analysis::check_crate
             19: rustc_interface::passes::analysis
             20: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), core::result::Result<(), rustc_errors::ErrorGuaranteed>>
             21: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
             22: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
             23: <rustc_interface::passes::QueryContext>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
             24: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorGuaranteed>>
             25: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
             26: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
             27: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
             28: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
             29: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/e1eaa2d5d4d1f5b7b89561a940718058d414e89c/library/alloc/src/boxed.rs:1988:9
             30: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/e1eaa2d5d4d1f5b7b89561a940718058d414e89c/library/alloc/src/boxed.rs:1988:9
             31: std::sys::unix::thread::Thread::new::thread_start
                        at /rustc/e1eaa2d5d4d1f5b7b89561a940718058d414e89c/library/std/src/sys/unix/thread.rs:108:17
             32: <unknown>
             33: <unknown>
           

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

note: rustc 1.69.0-nightly (e1eaa2d5d 2023-02-06) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
end of query stack
thread panicked while panicking. aborting.

@0xAda 0xAda 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 Feb 7, 2023
@0xAda 0xAda changed the title Type inference ICE with hashmap of async function pointers TypeError ICE with hashmap of async function pointers Feb 7, 2023
@compiler-errors compiler-errors self-assigned this Feb 7, 2023
@matthiaskrgr
Copy link
Member

Is this related to #107428 ?

@compiler-errors
Copy link
Member

Nope

@matthiaskrgr
Copy link
Member

Ooh I misread the Typerror ice, my bad 🙃

@compiler-errors
Copy link
Member

No big deal, this has to do with a lock (well, refcell) being held in hir typeck, if you're curious

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 8, 2023
…ckh726

Remove astconv usage in diagnostic

Fixes rust-lang#107775

Location of the test sucks, I know, but I needed to put it somewhere 😓
The issue here is that the root cause of the issue has nothing to do with what's being tested, so I couldn't really give it a better name. Oh well.
@bors bors closed this as completed in fe26182 Feb 8, 2023
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. 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.

3 participants