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 crashes on impl trait for async fn with unstable feature enabled #112347

Closed
clchiou opened this issue Jun 6, 2023 · 7 comments
Closed
Assignees
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` F-unboxed_closures `#![feature(unboxed_closures)]` glacier ICE tracked in rust-lang/glacier. 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

@clchiou
Copy link

clchiou commented Jun 6, 2023

The bug arose when I was implementing a trait for async functions. I tested this code in the playground, and the compiler also crashed.

Code

#![feature(associated_type_bounds)]
#![feature(unboxed_closures)]

use std::future::Future;

use async_trait::async_trait;

#[async_trait]
trait Trait<Arg0>
where
    Arg0: ?Sized,
{
    type Return;

    async fn func(&mut self, arg0: &Arg0) -> Self::Return;
}

#[async_trait]
impl<AsyncFn, Arg0, Return> Trait<Arg0> for AsyncFn
where
    for<'a> AsyncFn: Fn<(&'a Arg0,), Output: Future<Output = Return> + Send + 'a> + Send + Sync,
    Arg0: ?Sized + Sync,
{
    type Return = Return;

    async fn func(&mut self, arg0: &Arg0) -> Self::Return {
        self(arg0).await
    }
}

async fn strlen(x: &str) -> usize {
    x.len()
}

#[tokio::test]
async fn test() {
    assert_eq!(strlen.func("hello world").await, 11);
}

Playground link

Meta

rustc --version --verbose:

rustc 1.72.0-nightly (e6d4725c7 2023-06-05)
binary: rustc
commit-hash: e6d4725c76f3b526c74454bc51afdf6daf133506
commit-date: 2023-06-05
host: x86_64-unknown-linux-gnu
release: 1.72.0-nightly
LLVM version: 16.0.4

Error output

   Compiling playground v0.0.1 (/playground)
warning: function `strlen` is never used
  --> src/lib.rs:31:10
   |
31 | async fn strlen(x: &str) -> usize {
   |          ^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: `playground` (lib) generated 1 warning
thread 'rustc' panicked at 'future has no bound vars', compiler/rustc_trait_selection/src/traits/select/confirmation.rs:751:50
stack backtrace:
   0:     0x7f2d950caba1 - trace
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f2d950caba1 - trace_unsynchronized<std::sys_common::backtrace::_print_fmt::{closure_env#1}>
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f2d950caba1 - _print_fmt
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f2d950caba1 - fmt
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f2d9512b18f - fmt
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/core/src/fmt/rt.rs:138:9
   5:     0x7f2d9512b18f - write
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/core/src/fmt/mod.rs:1094:21
   6:     0x7f2d950bde51 - write_fmt<std::sys::unix::stdio::Stderr>
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/io/mod.rs:1713:15
   7:     0x7f2d950ca9b5 - _print
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f2d950ca9b5 - print
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f2d950cd677 - {closure#1}
  10:     0x7f2d950cd464 - default_hook
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/panicking.rs:288:9
  11:     0x7f2d983013eb - rustc_driver_impl[19f317ad306b3be2]::install_ice_hook::{closure#0}
  12:     0x7f2d950cddbd - call<(&core::panic::panic_info::PanicInfo), (dyn core::ops::function::Fn<(&core::panic::panic_info::PanicInfo), Output=()> + core::marker::Send + core::marker::Sync), alloc::alloc::Global>
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/alloc/src/boxed.rs:1999:9
  13:     0x7f2d950cddbd - rust_panic_with_hook
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/panicking.rs:709:13
  14:     0x7f2d950cdb57 - {closure#0}
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/panicking.rs:597:13
  15:     0x7f2d950cafd6 - __rust_end_short_backtrace<std::panicking::begin_panic_handler::{closure_env#0}, !>
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/sys_common/backtrace.rs:151:18
  16:     0x7f2d950cd8a2 - begin_panic_handler
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/panicking.rs:593:5
  17:     0x7f2d95127413 - panic_fmt
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/core/src/panicking.rs:67:14
  18:     0x7f2d95127183 - panic_display<&str>
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/core/src/panicking.rs:150:5
  19:     0x7f2d95127183 - panic_str
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/core/src/panicking.rs:134:5
  20:     0x7f2d95127183 - expect_failed
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/core/src/option.rs:1952:5
  21:     0x7f2d968c65ee - <rustc_trait_selection[1af287a7d6dc34a8]::traits::select::SelectionContext>::confirm_candidate
  22:     0x7f2d96b88bc8 - <rustc_trait_selection[1af287a7d6dc34a8]::traits::select::SelectionContext>::evaluate_stack
  23:     0x7f2d96cca1c7 - <rustc_trait_selection[1af287a7d6dc34a8]::traits::select::SelectionContext>::evaluate_predicate_recursively
  24:     0x7f2d96d52719 - rustc_traits[4f6015c626945177]::evaluate_obligation::evaluate_obligation
  25:     0x7f2d963396d2 - rustc_query_impl[1543b9ffeb56b6f4]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1543b9ffeb56b6f4]::query_impl::evaluate_obligation::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ef323c168d9384f4]::query::erase::Erased<[u8; 2usize]>>
  26:     0x7f2d96832152 - rustc_query_system[494966daf0575a9b]::query::plumbing::try_execute_query::<rustc_query_impl[1543b9ffeb56b6f4]::DynamicConfig<rustc_query_system[494966daf0575a9b]::query::caches::DefaultCache<rustc_middle[ef323c168d9384f4]::infer::canonical::Canonical<rustc_middle[ef323c168d9384f4]::ty::ParamEnvAnd<rustc_middle[ef323c168d9384f4]::ty::Predicate>>, rustc_middle[ef323c168d9384f4]::query::erase::Erased<[u8; 2usize]>>, false, false, false>, rustc_query_impl[1543b9ffeb56b6f4]::plumbing::QueryCtxt, false>
  27:     0x7f2d96831dbe - rustc_query_impl[1543b9ffeb56b6f4]::query_impl::evaluate_obligation::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7f2d965ed8bc - <rustc_infer[db35be7103d3010a]::infer::InferCtxt as rustc_trait_selection[1af287a7d6dc34a8]::traits::query::evaluate_obligation::InferCtxtExt>::predicate_must_hold_considering_regions
  29:     0x7f2d9659fa6d - <rustc_trait_selection[1af287a7d6dc34a8]::traits::fulfill::FulfillProcessor as rustc_data_structures[7856cba86f978d37]::obligation_forest::ObligationProcessor>::process_obligation
  30:     0x7f2d96596671 - <rustc_data_structures[7856cba86f978d37]::obligation_forest::ObligationForest<rustc_trait_selection[1af287a7d6dc34a8]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[1af287a7d6dc34a8]::traits::fulfill::FulfillProcessor>
  31:     0x7f2d96cd7b75 - <dyn rustc_infer[db35be7103d3010a]::traits::engine::TraitEngine as rustc_infer[db35be7103d3010a]::traits::engine::TraitEngineExt>::select_all_or_error
  32:     0x7f2d96cd6454 - rustc_traits[4f6015c626945177]::codegen::codegen_select_candidate
  33:     0x7f2d96381e4f - rustc_query_impl[1543b9ffeb56b6f4]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1543b9ffeb56b6f4]::query_impl::codegen_select_candidate::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ef323c168d9384f4]::query::erase::Erased<[u8; 16usize]>>
  34:     0x7f2d97477046 - rustc_query_system[494966daf0575a9b]::query::plumbing::try_execute_query::<rustc_query_impl[1543b9ffeb56b6f4]::DynamicConfig<rustc_query_system[494966daf0575a9b]::query::caches::DefaultCache<(rustc_middle[ef323c168d9384f4]::ty::ParamEnv, rustc_middle[ef323c168d9384f4]::ty::sty::Binder<rustc_middle[ef323c168d9384f4]::ty::sty::TraitRef>), rustc_middle[ef323c168d9384f4]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[1543b9ffeb56b6f4]::plumbing::QueryCtxt, false>
  35:     0x7f2d97476cca - rustc_query_impl[1543b9ffeb56b6f4]::query_impl::codegen_select_candidate::get_query_non_incr::__rust_end_short_backtrace
  36:     0x7f2d970301c1 - rustc_ty_utils[14fb50b748d4fe37]::instance::resolve_instance
  37:     0x7f2d9633f55c - rustc_query_impl[1543b9ffeb56b6f4]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1543b9ffeb56b6f4]::query_impl::resolve_instance::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ef323c168d9384f4]::query::erase::Erased<[u8; 32usize]>>
  38:     0x7f2d96bda7d3 - rustc_query_system[494966daf0575a9b]::query::plumbing::try_execute_query::<rustc_query_impl[1543b9ffeb56b6f4]::DynamicConfig<rustc_query_system[494966daf0575a9b]::query::caches::DefaultCache<rustc_middle[ef323c168d9384f4]::ty::ParamEnvAnd<(rustc_span[c9fd14582bbb5db9]::def_id::DefId, &rustc_middle[ef323c168d9384f4]::ty::list::List<rustc_middle[ef323c168d9384f4]::ty::subst::GenericArg>)>, rustc_middle[ef323c168d9384f4]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[1543b9ffeb56b6f4]::plumbing::QueryCtxt, false>
  39:     0x7f2d96bda444 - rustc_query_impl[1543b9ffeb56b6f4]::query_impl::resolve_instance::get_query_non_incr::__rust_end_short_backtrace
  40:     0x7f2d96f2ebcc - rustc_monomorphize[93680276fc04688]::collector::collect_used_items
  41:     0x7f2d96f25bf3 - rustc_monomorphize[93680276fc04688]::collector::collect_items_rec
  42:     0x7f2d96f26524 - rustc_monomorphize[93680276fc04688]::collector::collect_items_rec
  43:     0x7f2d96f26524 - rustc_monomorphize[93680276fc04688]::collector::collect_items_rec
  44:     0x7f2d96f26524 - rustc_monomorphize[93680276fc04688]::collector::collect_items_rec
  45:     0x7f2d974f1363 - rustc_data_structures[7856cba86f978d37]::sync::par_for_each_in::<alloc[bb2455db20450995]::vec::Vec<rustc_middle[ef323c168d9384f4]::mir::mono::MonoItem>, rustc_monomorphize[93680276fc04688]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>
  46:     0x7f2d974f1020 - <rustc_session[23023510f27a6956]::session::Session>::time::<(), rustc_monomorphize[93680276fc04688]::collector::collect_crate_mono_items::{closure#1}>
  47:     0x7f2d974f0c68 - rustc_monomorphize[93680276fc04688]::collector::collect_crate_mono_items
  48:     0x7f2d974ef3f7 - rustc_monomorphize[93680276fc04688]::partitioning::collect_and_partition_mono_items
  49:     0x7f2d97900059 - rustc_query_impl[1543b9ffeb56b6f4]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1543b9ffeb56b6f4]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ef323c168d9384f4]::query::erase::Erased<[u8; 24usize]>>
  50:     0x7f2d9790002b - <rustc_query_impl[1543b9ffeb56b6f4]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[89b1b7d1b31a1e7d]::ops::function::FnOnce<(rustc_middle[ef323c168d9384f4]::ty::context::TyCtxt, ())>>::call_once
  51:     0x7f2d97a0ed4c - rustc_query_system[494966daf0575a9b]::query::plumbing::try_execute_query::<rustc_query_impl[1543b9ffeb56b6f4]::DynamicConfig<rustc_query_system[494966daf0575a9b]::query::caches::SingleCache<rustc_middle[ef323c168d9384f4]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[1543b9ffeb56b6f4]::plumbing::QueryCtxt, false>
  52:     0x7f2d97c8e444 - rustc_query_impl[1543b9ffeb56b6f4]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  53:     0x7f2d97967546 - rustc_codegen_ssa[3134fc578afcf247]::base::codegen_crate::<rustc_codegen_llvm[7c63b95a4e813ac8]::LlvmCodegenBackend>
  54:     0x7f2d9796732f - <rustc_codegen_llvm[7c63b95a4e813ac8]::LlvmCodegenBackend as rustc_codegen_ssa[3134fc578afcf247]::traits::backend::CodegenBackend>::codegen_crate
  55:     0x7f2d97541d32 - <rustc_session[23023510f27a6956]::session::Session>::time::<alloc[bb2455db20450995]::boxed::Box<dyn core[89b1b7d1b31a1e7d]::any::Any>, rustc_interface[e4001d1c190a5888]::passes::start_codegen::{closure#0}>
  56:     0x7f2d9754187b - rustc_interface[e4001d1c190a5888]::passes::start_codegen
  57:     0x7f2d9753d06d - <rustc_middle[ef323c168d9384f4]::ty::context::GlobalCtxt>::enter::<<rustc_interface[e4001d1c190a5888]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[89b1b7d1b31a1e7d]::result::Result<alloc[bb2455db20450995]::boxed::Box<dyn core[89b1b7d1b31a1e7d]::any::Any>, rustc_span[c9fd14582bbb5db9]::ErrorGuaranteed>>
  58:     0x7f2d9753b7bd - <rustc_interface[e4001d1c190a5888]::queries::Queries>::ongoing_codegen
  59:     0x7f2d9753ad94 - <rustc_interface[e4001d1c190a5888]::interface::Compiler>::enter::<rustc_driver_impl[19f317ad306b3be2]::run_compiler::{closure#1}::{closure#2}, core[89b1b7d1b31a1e7d]::result::Result<core[89b1b7d1b31a1e7d]::option::Option<rustc_interface[e4001d1c190a5888]::queries::Linker>, rustc_span[c9fd14582bbb5db9]::ErrorGuaranteed>>
  60:     0x7f2d97538370 - std[4cc418835f9904b9]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[e4001d1c190a5888]::util::run_in_thread_pool_with_globals<rustc_interface[e4001d1c190a5888]::interface::run_compiler<core[89b1b7d1b31a1e7d]::result::Result<(), rustc_span[c9fd14582bbb5db9]::ErrorGuaranteed>, rustc_driver_impl[19f317ad306b3be2]::run_compiler::{closure#1}>::{closure#0}, core[89b1b7d1b31a1e7d]::result::Result<(), rustc_span[c9fd14582bbb5db9]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[89b1b7d1b31a1e7d]::result::Result<(), rustc_span[c9fd14582bbb5db9]::ErrorGuaranteed>>
  61:     0x7f2d97537b15 - <<std[4cc418835f9904b9]::thread::Builder>::spawn_unchecked_<rustc_interface[e4001d1c190a5888]::util::run_in_thread_pool_with_globals<rustc_interface[e4001d1c190a5888]::interface::run_compiler<core[89b1b7d1b31a1e7d]::result::Result<(), rustc_span[c9fd14582bbb5db9]::ErrorGuaranteed>, rustc_driver_impl[19f317ad306b3be2]::run_compiler::{closure#1}>::{closure#0}, core[89b1b7d1b31a1e7d]::result::Result<(), rustc_span[c9fd14582bbb5db9]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[89b1b7d1b31a1e7d]::result::Result<(), rustc_span[c9fd14582bbb5db9]::ErrorGuaranteed>>::{closure#1} as core[89b1b7d1b31a1e7d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  62:     0x7f2d950d82b5 - call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/alloc/src/boxed.rs:1985:9
  63:     0x7f2d950d82b5 - call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global>
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/alloc/src/boxed.rs:1985:9
  64:     0x7f2d950d82b5 - thread_start
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/sys/unix/thread.rs:108:17
  65:     0x7f2d94fa6609 - start_thread
  66:     0x7f2d94ec9133 - clone
  67:                0x0 - <unknown>

error: 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.72.0-nightly (e6d4725c7 2023-06-05) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

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

query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `for<'a> [async fn body@src/lib.rs:31:35: 33:2]: core::future::future::Future`
#1 [codegen_select_candidate] computing candidate for `<strlen as Trait<str>>`
#2 [resolve_instance] resolving instance `<strlen as Trait<str>>::func::<'_, '_, '_>`
#3 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: could not compile `playground` (lib test)
Backtrace

RUST_BACKTRACE=1 cargo build

thread 'rustc' panicked at 'future has no bound vars', compiler/rustc_trait_selection/src/traits/select/confirmation.rs:751:50
stack backtrace:
   0: begin_panic_handler
             at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/panicking.rs:593:5
   1: panic_fmt
             at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/core/src/panicking.rs:67:14
   2: panic_display<&str>
             at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/core/src/panicking.rs:150:5
   3: panic_str
             at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/core/src/panicking.rs:134:5
   4: expect_failed
             at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/core/src/option.rs:1952:5
   5: <rustc_trait_selection::traits::select::SelectionContext>::confirm_candidate
   6: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_stack
   7: <rustc_middle::dep_graph::dep_node::DepKind as rustc_query_system::dep_graph::DepKind>::with_deps::<<rustc_trait_selection::traits::select::SelectionContext>::in_task<<rustc_trait_selection::traits::select::SelectionContext>::evaluate_trait_predicate_recursively::{closure#0}::{closure#2}, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>>::{closure#0}, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>>
   8: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_predicate_recursively
   9: rustc_traits::evaluate_obligation::evaluate_obligation
  10: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::predicate_must_hold_considering_regions
  11: <rustc_trait_selection::traits::fulfill::FulfillProcessor as rustc_data_structures::obligation_forest::ObligationProcessor>::process_obligation
  12: <rustc_data_structures::obligation_forest::ObligationForest<rustc_trait_selection::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection::traits::fulfill::FulfillProcessor>
  13: <dyn rustc_infer::traits::engine::TraitEngine as rustc_infer::traits::engine::TraitEngineExt>::select_all_or_error
  14: rustc_traits::codegen::codegen_select_candidate
  15: rustc_ty_utils::instance::resolve_instance
  16: rustc_monomorphize::collector::collect_used_items
  17: rustc_monomorphize::collector::collect_items_rec
  18: rustc_monomorphize::collector::collect_items_rec
  19: rustc_monomorphize::collector::collect_items_rec
  20: rustc_monomorphize::collector::collect_items_rec
  21: rustc_monomorphize::collector::collect_items_rec
  22: rustc_monomorphize::collector::collect_items_rec
  23: rustc_monomorphize::collector::collect_items_rec
  24: rustc_monomorphize::collector::collect_items_rec
  25: rustc_monomorphize::collector::collect_items_rec
  26: rustc_data_structures::sync::par_for_each_in::<alloc::vec::Vec<rustc_middle::mir::mono::MonoItem>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure#0}>
  27: <rustc_session::session::Session>::time::<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}>
  28: rustc_monomorphize::collector::collect_crate_mono_items
  29: rustc_monomorphize::partitioning::collect_and_partition_mono_items
  30: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
  31: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  32: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
  33: rustc_interface::passes::start_codegen
  34: <rustc_middle::ty::context::GlobalCtxt>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core::result::Result<alloc::boxed::Box<dyn core::any::Any>, rustc_span::ErrorGuaranteed>>
  35: <rustc_interface::queries::Queries>::ongoing_codegen
  36: <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_span::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: 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.72.0-nightly (e6d4725c7 2023-06-05) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -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:
#0 [evaluate_obligation] evaluating trait selection obligation `for<'a> [async fn body@src/bin/compiler-crash.rs:31:35: 33:2]: core::future::future::Future`
#1 [codegen_select_candidate] computing candidate for `<strlen as Trait<str>>`
#2 [resolve_instance] resolving instance `<strlen as Trait<str>>::func::<'_, '_, '_>`
#3 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack

@clchiou clchiou 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 6, 2023
@clchiou
Copy link
Author

clchiou commented Jun 6, 2023

In the playground, Build does not crash. You will have to click Test to make it crash.

@compiler-errors
Copy link
Member

Not related to associated_type_bounds:

#![feature(unboxed_closures)]

use std::future::Future;

use async_trait::async_trait;

#[async_trait]
trait Trait<Arg0>
where
    Arg0: ?Sized,
{
    type Return;

    async fn func(&mut self, arg0: &Arg0) -> Self::Return;
}

#[async_trait]
impl<AsyncFn, Arg0, Return> Trait<Arg0> for AsyncFn
where
    for<'a> AsyncFn: Fn<(&'a Arg0,)> + Send + Sync,
    for<'a> <AsyncFn as FnOnce<(&'a Arg0,)>>::Output: Future<Output = Return> + Send + 'a,
    Arg0: ?Sized + Sync,
{
    type Return = Return;

    async fn func(&mut self, arg0: &Arg0) -> Self::Return {
        self(arg0).await
    }
}

async fn strlen(x: &str) -> usize {
    x.len()
}

#[tokio::main]
async fn main() {
    assert_eq!(strlen.func("hello world").await, 11);
}

Could be further minimized, I think.

@clchiou
Copy link
Author

clchiou commented Jun 7, 2023

Thanks for the improvement.

I did a small experiment. I found that type Return can be safely removed. However, when I changed Arg0 from a reference to a non-reference, the compiler passed. In other words, async f<T>(T) passes, but async f<T>(&T) crashes.

@dswij
Copy link
Member

dswij commented Jun 21, 2023

@rustbot claim

@dswij
Copy link
Member

dswij commented Jun 21, 2023

Can be further minimized to:

#![feature(unboxed_closures)]

use std::future::Future;

trait Trait {
    fn func(&self, _: &str);
}

impl<T> Trait for T
where
    for<'a> T: Fn<(&'a str,)> + Send + Sync,
    for<'a> <T as FnOnce<(&'a str,)>>::Output: Future<Output = usize> + Send,
{
    fn func(&self, _: &str) {
        println!("hello!");
    }
}

async fn strlen(x: &str) -> usize {
    x.len()
}

fn main() {
    strlen.func("hi");
}

The problem is because Futures doesn't expect bounds when resolving, but is given here with HRTB.

@compiler-errors
Copy link
Member

Here's an even more minimal example, that only relies on type_alias_impl_trait which I assume we want to stabilize sooner than unboxed_closures 😄

#![feature(type_alias_impl_trait)]

use std::future::Future;

type Fut<'a> = impl Future<Output = ()> + 'a;

fn foo<'a>(_: &()) -> Fut<'_> {
    async {}
}

trait Test {
    fn hello();
}

impl Test for ()
where
    for<'a> Fut<'a>: Future<Output = ()>,
{
    fn hello() {}
}

fn main() {
    <()>::hello();
}

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 25, 2023
Add test for futures with HRTB

Part of rust-lang#112347

This PR adds test for ice when resolving for `Futures` with HRTB.
@albertlarsan68
Copy link
Member

@compiler-errors Your minimisation doesn't work on latest nightly (2023-07-12), but @dswij's still works

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jul 14, 2023
@fmease fmease added F-associated_type_bounds `#![feature(associated_type_bounds)]` F-unboxed_closures `#![feature(unboxed_closures)]` F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` and removed F-associated_type_bounds `#![feature(associated_type_bounds)]` labels Mar 1, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 18, 2024
…r=<try>

Eagerly instantiate closure/coroutine-like bounds with placeholders to deal with binders correctly

A follow-up to rust-lang#119849, however it aims to fix a different set of issues. Currently, we have trouble confirming goals where built-in closure/fnptr/coroutine signatures are compared against higher-ranked goals.

Currently, we don't support goals like `for<'a> fn(&'a ()): Fn(&'a ())` because we don't expect the self type of goal to reference any bound regions from the goal, because we don't really know how to deal with the double binder of predicate + self type. However, this definitely can be reached (rust-lang#121653) -- and in fact, it results in post-mono errors in the case of rust-lang#112347 where the builtin type (e.g. a coroutine) is hidden behind a TAIT.

The proper fix here is to instantiate the goal before trying to extract the signature from the self type. See final two commits.

r? lcnr
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 2, 2024
…r=lcnr

Eagerly instantiate closure/coroutine-like bounds with placeholders to deal with binders correctly

A follow-up to rust-lang#119849, however it aims to fix a different set of issues. Currently, we have trouble confirming goals where built-in closure/fnptr/coroutine signatures are compared against higher-ranked goals.

Currently, we don't support goals like `for<'a> fn(&'a ()): Fn(&'a ())` because we don't expect the self type of goal to reference any bound regions from the goal, because we don't really know how to deal with the double binder of predicate + self type. However, this definitely can be reached (rust-lang#121653) -- and in fact, it results in post-mono errors in the case of rust-lang#112347 where the builtin type (e.g. a coroutine) is hidden behind a TAIT.

The proper fix here is to instantiate the goal before trying to extract the signature from the self type. See final two commits.

r? lcnr
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 27, 2024
@bors bors closed this as completed in 27338f2 Apr 28, 2024
blyxyas pushed a commit to blyxyas/rust that referenced this issue Apr 28, 2024
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. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` F-unboxed_closures `#![feature(unboxed_closures)]` glacier ICE tracked in rust-lang/glacier. 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

No branches or pull requests

6 participants