rust-lang / rust

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

thread 'rustc' panicked at 'assertion failed: !erased_self_ty.has_escaping_bound_vars()' #86800

Closed fourbytes closed 1 year ago

fourbytes commented 3 years ago

Code

#![feature(min_type_alias_impl_trait)]
use std::future::Future;

struct Connection {
}

trait Transaction {
}

struct TestTransaction<'conn> {
    conn: &'conn Connection
}

impl<'conn> Transaction for TestTransaction<'conn> {
}

struct Context {
}

type TransactionResult<O> = Result<O, ()>;

type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;

fn execute_transaction_fut<'f, F, O>(f: F) -> impl FnOnce(&mut dyn Transaction) -> TransactionFuture<O>
where
    F: FnOnce(&mut dyn Transaction) -> TransactionFuture<O> + 'f
{
    f
}

impl Context {
    async fn do_transaction<O>(
        &self, f: impl FnOnce(&mut dyn Transaction) -> TransactionFuture<O>
    ) -> TransactionResult<O>
    {
        let mut conn = Connection {};
        let mut transaction = TestTransaction { conn: &mut conn };
        f(&mut transaction).await
    }
}

Meta

rustc --version --verbose:

rustc 1.55.0-nightly (a435b49e8 2021-06-28)
binary: rustc
commit-hash: a435b49e86d16e98dcc6595dd471f95e823f41aa
commit-date: 2021-06-28
host: x86_64-apple-darwin
release: 1.55.0-nightly
LLVM version: 12.0.1

Error output

thread 'rustc' panicked at 'assertion failed: !erased_self_ty.has_escaping_bound_vars()', compiler/rustc_trait_selection/src/opaque_types.rs:1182:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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.55.0-nightly (a435b49e8 2021-06-28) running on x86_64-apple-darwin

note: compiler flags: -C opt-level=3 -C embed-bitcode=no --crate-type bin

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

query stack during panic:
#0 [typeck] type-checking `ice1::execute_transaction_fut`
#1 [type_of] computing type of `ice1::TransactionFuture::{opaque#0}`
end of query stack
error: could not compile `rust-playground`
Backtrace

``` Compiling rust-playground v0.1.0 (/Users/fourbytes/Projects/rust-playground) thread 'rustc' panicked at 'assertion failed: !erased_self_ty.has_escaping_bound_vars()', compiler/rustc_trait_selection/src/opaque_types.rs:1182:5 stack backtrace: 0: _rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: rustc_trait_selection::opaque_types::Instantiator::fold_opaque_ty 4: as rustc_middle::ty::fold::TypeFolder>::fold_ty 5: rustc_middle::ty::fold::TypeFoldable::fold_with 6: rustc_trait_selection::opaque_types::Instantiator::fold_opaque_ty 7: as rustc_middle::ty::fold::TypeFolder>::fold_ty 8: rustc_typeck::check::fn_ctxt::_impl::::instantiate_opaque_types_from_value 9: rustc_typeck::check::check::check_fn 10: rustc_infer::infer::InferCtxtBuilder::enter 11: rustc_typeck::check::typeck 12: rustc_query_system::dep_graph::graph::DepGraph::with_task_impl 13: rustc_data_structures::stack::ensure_sufficient_stack 14: rustc_query_system::query::plumbing::force_query_with_job 15: rustc_query_system::query::plumbing::get_query_impl 16: ::typeck 17: rustc_typeck::collect::type_of::find_opaque_ty_constraints::ConstraintLocator::check 18: rustc_hir::intravisit::walk_item 19: rustc_typeck::collect::type_of::type_of 20: rustc_query_system::dep_graph::graph::DepGraph::with_task_impl 21: rustc_data_structures::stack::ensure_sufficient_stack 22: rustc_query_system::query::plumbing::force_query_with_job 23: rustc_query_system::query::plumbing::get_query_impl 24: ::type_of 25: rustc_typeck::check::check::check_item_type 26: rustc_middle::hir::map::Map::visit_item_likes_in_module 27: rustc_typeck::check::check::check_mod_item_types 28: rustc_query_system::dep_graph::graph::DepGraph::with_task_impl 29: rustc_data_structures::stack::ensure_sufficient_stack 30: rustc_query_system::query::plumbing::force_query_with_job 31: rustc_query_system::query::plumbing::get_query_impl 32: ::check_mod_item_types 33: rustc_session::utils::::time 34: rustc_typeck::check_crate 35: rustc_interface::passes::analysis 36: rustc_query_system::dep_graph::graph::DepGraph::with_task_impl 37: rustc_data_structures::stack::ensure_sufficient_stack 38: rustc_query_system::query::plumbing::force_query_with_job 39: rustc_query_system::query::plumbing::get_query_impl 40: ::analysis 41: rustc_interface::queries::::enter 42: rustc_span::with_source_map 43: rustc_interface::interface::create_compiler_and_run 44: scoped_tls::ScopedKey::set note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. error: internal compiler error: unexpected panic 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.55.0-nightly (a435b49e8 2021-06-28) running on x86_64-apple-darwin note: compiler flags: -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental --crate-type bin note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [typeck] type-checking `ice1::execute_transaction_fut` #1 [type_of] computing type of `ice1::TransactionFuture::{opaque#0}` #2 [check_mod_item_types] checking item types in module `ice1` #3 [analysis] running analysis passes on this crate end of query stack error: could not compile `rust-playground` To learn more, run the command again with --verbose. ```

FabianWolff commented 3 years ago

Might be related to #83693.

compiler-errors commented 2 years ago

Re-opening due to #99860

langston-barrett commented 1 year ago

Here's a more minimal version:

type TransactionFuture<'__, O> = impl '__;
fn execute_transaction_fut<'f, F, O>() -> FnOnce(&Transaction) -> TransactionFuture<'_, O> {
    f
}

This gives a slightly different error message, probably just due to updates in rustc since when this was first filed.

error: internal compiler error: compiler/rustc_hir_typeck/src/inherited.rs:130:13: escaping bound vars in predicate Obligation(predicate=Binder(TraitPredicate(<TransactionFuture<'_, O> as std::marker::Sized>, polarity:Positive), []), depth=0)
 --> ice_min.rs:2:43
  |
2 | fn execute_transaction_fut<'f, F, O>() -> FnOnce(&Transaction) -> TransactionFuture<'_, O> {
  |                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
rustc 1.70.0-nightly (ff4b772f8 2023-03-10)
binary: rustc
commit-hash: ff4b772f805ec1e1c1bd7e189ab8d5a4e3a6ef13
commit-date: 2023-03-10
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 15.0.7

Minimized with treereduce.

JohnTitor commented 1 year ago

Triage: Fixed on the latest nightly, @rustbot labels: +E-needs-test