Repository: rust
Issue: ICE: could not fully normalize (wrap + foundationdb)
Labels: I-ICE,T-compiler,C-bug,E-needs-mcve

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.

http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/

-->

### Code

```Rust
use futures::prelude::*;
use std::pin::Pin;
use warp::{Filter, Reply};

struct Database;

pub trait DatabaseTransact {
    type Item;
}

pub struct FnMutBoxed<F> {
    pub f: F,
}
impl<F> DatabaseTransact for FnMutBoxed<F>
where
    F: FnMut() -> Pin<Box<dyn Future<Output = ()> + Send>>,
{
    type Item = ();
}

impl Database {
    pub fn transact_boxed<F>(f: F) -> impl Future<Output = ()> + Send + 'static
    where
        F: FnMut() -> Pin<Box<dyn Future<Output = ()> + Send>>,
        F: Send + 'static,
    {
        Self::transact(FnMutBoxed { f })
    }

    pub async fn transact<F>(_f: F) -> F::Item
    where
        F: DatabaseTransact,
    {
        todo!()
    }
}
pub async fn test1() -> std::result::Result<impl Reply, warp::Rejection> {
    Database::transact_boxed(|| futures::future::ready(()).boxed()).await;
    Ok(warp::reply::json(&"test 1"))
}

fn main() {
    futures::executor::block_on(
        warp::serve(warp::get().and_then(test1)).run(([127, 0, 0, 1], 8010)),
    );
}
```


### Meta


`rustc --version --verbose`:
```
rustc 1.53.0-nightly (7f4afdf02 2021-04-22)
binary: rustc
commit-hash: 7f4afdf0255600306bf67432da722c7b5d2cbf82
commit-date: 2021-04-22
host: x86_64-pc-windows-msvc
release: 1.53.0-nightly
LLVM version: 12.0.0
```

Same with stable (`rustc 1.51.0 (2fd73fabe 2021-03-23) running on x86_64-pc-windows-msvc`)

### Error output

```
error: internal compiler error: compiler\rustc_traits\src\normalize_erasing_regions.rs:54:32: could not fully normalize `fn([closure@warp::Server<warp::filter::and_then::AndThen<warp::filter::FilterFn<[closure@warp::filters::method::method_is<[closure@warp::get::{closure#0}]>::{closure#0}]>, fn() -> impl futures::Future {test1}>>::bind_ephemeral<([u8; 4], u16)>::{closure#0}], <warp::hyper::Server<warp::hyper::server::conn::AddrIncoming, warp::hyper::service::make::MakeServiceFn<[closure@warp::Server<warp::filter::and_then::AndThen<warp::filter::FilterFn<[closure@warp::filters::method::method_is<[closure@warp::get::{closure#0}]>::{closure#0}]>, fn() -> impl futures::Future {test1}>>::bind_ephemeral<([u8; 4], u16)>::{closure#1}::{closure#0}]>> as futures::Future>::Output) -> <[closure@warp::Server<warp::filter::and_then::AndThen<warp::filter::FilterFn<[closure@warp::filters::method::method_is<[closure@warp::get::{closure#0}]>::{closure#0}]>, 
fn() -> impl futures::Future {test1}>>::bind_ephemeral<([u8; 4], u16)>::{closure#0}] as futures_util::fns::FnOnce1<<warp::hyper::Server<warp::hyper::server::conn::AddrIncoming, warp::hyper::service::make::MakeServiceFn<[closure@warp::Server<warp::filter::and_then::AndThen<warp::filter::FilterFn<[closure@warp::filters::method::method_is<[closure@warp::get::{closure#0}]>::{closure#0}]>, fn() -> impl futures::Future {test1}>>::bind_ephemeral<([u8; 4], u16)>::{closure#1}::{closure#0}]>> as futures::Future>::Output>>::Output {<[closure@warp::Server<warp::filter::and_then::AndThen<warp::filter::FilterFn<[closure@warp::filters::method::method_is<[closure@warp::get::{closure#0}]>::{closure#0}]>, fn() -> impl futures::Future {test1}>>::bind_ephemeral<([u8; 4], u16)>::{closure#0}] as futures_util::fns::FnOnce1<<warp::hyper::Server<warp::hyper::server::conn::AddrIncoming, warp::hyper::service::make::MakeServiceFn<[closure@warp::Server<warp::filter::and_then::AndThen<warp::filter::FilterFn<[closure@warp::filters::method::method_is<[closure@warp::get::{closure#0}]>::{closure#0}]>, fn() -> impl futures::Future {test1}>>::bind_ephemeral<([u8; 4], u16)>::{closure#1}::{closure#0}]>> as futures::Future>::Output>>::call_once}`
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Backtrace</strong></summary>
<p>

```
thread 'rustc' panicked at 'Box<Any>', /rustc/7f4afdf0255600306bf67432da722c7b5d2cbf82\library\std\src\panic.rs:59:5
stack backtrace:
   0:     0x7ff89f3c5b8e - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h65f771762210e3e5
   1:     0x7ff89f3eedac - core::fmt::write::h3d73561f801c6731
   2:     0x7ff89f3b9c28 - <std::io::IoSliceMut as core::fmt::Debug>::fmt::hd8fe844d61210e6f
   3:     0x7ff89f3c9c82 - std::panicking::take_hook::ha49dee799706a2d8
   4:     0x7ff89f3c9774 - std::panicking::take_hook::ha49dee799706a2d8
   5:     0x7ff8903fb2a7 - rustc_driver::report_ice::hab89c69e12b6dd11
   6:     0x7ff89f3ca465 - std::panicking::rust_panic_with_hook::h9e7cc259d68b1de2
   7:     0x7ff894529de0 - <rustc_errors::json::Diagnostic::from_errors_diagnostic::BufWriter as std::io::Write>::flush::h8891f669af2106fb
   8:     0x7ff894529389 - <rustc_errors::json::Diagnostic::from_errors_diagnostic::BufWriter as std::io::Write>::flush::h8891f669af2106fb
   9:     0x7ff8947b4b51 - rustc_query_system::query::job::report_cycle::hf9b212d4fcbb24d3
  10:     0x7ff8944f1070 - <rustc_feature::builtin_attrs::AttributeType as core::fmt::Debug>::fmt::hd792e56b30cee48c
  11:     0x7ff8944f7ab5 - rustc_errors::HandlerInner::err_count::h19c4a44295f74637
  12:     0x7ff8944f55c2 - rustc_errors::Handler::bug::ha6863da4b058abe7
  13:     0x7ff8943af3e8 - <rustc_middle::ty::sty::Binder<rustc_middle::ty::ProjectionPredicate> as rustc_middle::ty::ToPredicate>::to_predicate::h33b1b2f898ff3cca
  14:     0x7ff8943a3b70 - rustc_middle::ty::query::on_disk_cache::<impl rustc_serialize::serialize::Decodable<rustc_middle::ty::query::on_disk_cache::CacheDecoder> for &[rustc_middle::mir::abstract_const::Node]>::decode::h05252040febd0b50
  15:     0x7ff8943a3ab9 - rustc_middle::ty::query::on_disk_cache::<impl rustc_serialize::serialize::Decodable<rustc_middle::ty::query::on_disk_cache::CacheDecoder> for &[rustc_middle::mir::abstract_const::Node]>::decode::h05252040febd0b50
  16:     0x7ff8943af319 - <rustc_middle::ty::sty::Binder<rustc_middle::ty::ProjectionPredicate> as rustc_middle::ty::ToPredicate>::to_predicate::h33b1b2f898ff3cca
  17:     0x7ff8947ad4b7 - rustc_middle::util::bug::bug_fmt::he9e2e7924f44d34c
  18:     0x7ff89272c629 - rustc_traits::provide::hd4707f2be3930568
  19:     0x7ff8927f6a43 - <rustc_middle::traits::chalk::ChalkEnvironmentAndGoal as rustc_traits::chalk::lowering::LowerInto<chalk_ir::InEnvironment<chalk_ir::Goal<rustc_middle::traits::chalk::RustInterner>>>>::lower_into::he129e20208932df5
  20:     0x7ff8931d9752 - <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::try_print_query_stack::h3c4346cc01dbde58
  21:     0x7ff893169335 - rustc_query_impl::<impl rustc_query_system::query::config::QueryAccessors<rustc_query_impl::plumbing::QueryCtxt> for rustc_query_impl::queries::resolve_instance>::hash_result::hc7ba1ed25ba761ff
  22:     0x7ff892fe0b2c - <rustc_ast_lowering::item::ItemLowerer as rustc_ast::visit::Visitor>::visit_foreign_item::hbd68f25166d1e477
  23:     0x7ff892f4ecc5 - <rustc_ast_lowering::item::ItemLowerer as rustc_ast::visit::Visitor>::visit_foreign_item::hbd68f25166d1e477
  24:     0x7ff892ecb088 - <rustc_ast_lowering::item::ItemLowerer as rustc_ast::visit::Visitor>::visit_foreign_item::hbd68f25166d1e477
  25:     0x7ff8931c87ae - <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::try_print_query_stack::h3c4346cc01dbde58
  26:     0x7ff8943538fa - <rustc_middle::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder as rustc_middle::ty::fold::TypeFolder>::fold_ty::had7cf8d64e8d7d3e
  27:     0x7ff8934ca183 - <rustc_mir::monomorphize::collector::MirNeighborCollector as rustc_middle::mir::visit::Visitor>::visit_terminator::h1b9fec5ded037d3c  28:     0x7ff8934cd690 - <rustc_mir::monomorphize::collector::RootCollector as rustc_hir::itemlikevisit::ItemLikeVisitor>::visit_impl_item::hfb7712f4efbd0644  29:     0x7ff8934c61dd - rustc_mir::monomorphize::collector::collect_crate_mono_items::hbeb6d2045a60cd71
  30:     0x7ff8934c5ad2 - rustc_mir::monomorphize::collector::collect_crate_mono_items::hbeb6d2045a60cd71
  31:     0x7ff8934c5ad2 - rustc_mir::monomorphize::collector::collect_crate_mono_items::hbeb6d2045a60cd71
  32:     0x7ff8934c5ad2 - rustc_mir::monomorphize::collector::collect_crate_mono_items::hbeb6d2045a60cd71
  33:     0x7ff8934c5ad2 - rustc_mir::monomorphize::collector::collect_crate_mono_items::hbeb6d2045a60cd71
  34:     0x7ff8934c5ad2 - rustc_mir::monomorphize::collector::collect_crate_mono_items::hbeb6d2045a60cd71
  35:     0x7ff8934c5ad2 - rustc_mir::monomorphize::collector::collect_crate_mono_items::hbeb6d2045a60cd71
  36:     0x7ff8934c5ad2 - rustc_mir::monomorphize::collector::collect_crate_mono_items::hbeb6d2045a60cd71
  37:     0x7ff8934c5ad2 - rustc_mir::monomorphize::collector::collect_crate_mono_items::hbeb6d2045a60cd71
  38:     0x7ff8934c5ad2 - rustc_mir::monomorphize::collector::collect_crate_mono_items::hbeb6d2045a60cd71
  39:     0x7ff8934c5ad2 - rustc_mir::monomorphize::collector::collect_crate_mono_items::hbeb6d2045a60cd71
  40:     0x7ff8934c5ad2 - rustc_mir::monomorphize::collector::collect_crate_mono_items::hbeb6d2045a60cd71
  41:     0x7ff8937dcb5c - <rustc_mir::transform::rustc_peek::PeekCall as core::fmt::Debug>::fmt::ha1d73c9f560ce7e8
  42:     0x7ff8934c4351 - rustc_mir::monomorphize::collector::collect_crate_mono_items::hbeb6d2045a60cd71
  43:     0x7ff89382455d - rustc_mir::monomorphize::partitioning::partition::h4e4f3b68f0632de5
  44:     0x7ff892fbc7ef - <rustc_ast_lowering::item::ItemLowerer as rustc_ast::visit::Visitor>::visit_foreign_item::hbd68f25166d1e477
  45:     0x7ff8931d6e61 - <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::try_print_query_stack::h3c4346cc01dbde58
  46:     0x7ff8931786f5 - rustc_query_impl::<impl rustc_query_system::query::config::QueryAccessors<rustc_query_impl::plumbing::QueryCtxt> for rustc_query_impl::queries::resolve_instance>::hash_result::hc7ba1ed25ba761ff
  47:     0x7ff8930067ab - <rustc_ast_lowering::item::ItemLowerer as rustc_ast::visit::Visitor>::visit_foreign_item::hbd68f25166d1e477
  48:     0x7ff892f1679b - <rustc_ast_lowering::item::ItemLowerer as rustc_ast::visit::Visitor>::visit_foreign_item::hbd68f25166d1e477
  49:     0x7ff892ea297b - <rustc_ast_lowering::item::ItemLowerer as rustc_ast::visit::Visitor>::visit_foreign_item::hbd68f25166d1e477
  50:     0x7ff8931c8118 - <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::try_print_query_stack::h3c4346cc01dbde58
  51:     0x7ff89066d687 - <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::link::h47437b1deee45a0d
  52:     0x7ff89066a199 - <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate::h3f7a7161df43cead    
  53:     0x7ff8905327f2 - rustc_interface::passes::BoxedResolver::to_resolver_outputs::h51cffbb6bc3edf8f
  54:     0x7ff890549ff6 - rustc_interface::queries::Queries::ongoing_codegen::h30f27fdc61a86ed6
  55:     0x7ff890405a77 - rustc_driver::pretty::print_after_hir_lowering::h018530f73994254f
  56:     0x7ff8903fd9dc - <rustc_driver::Compilation as core::fmt::Debug>::fmt::h4409e290eea8174b
  57:     0x7ff890406d56 - rustc_driver::pretty::print_after_hir_lowering::h018530f73994254f
  58:     0x7ff89042d0e4 - <rustc_middle::ty::SymbolName as core::fmt::Debug>::fmt::ha51d28018e278c75
  59:     0x7ff89042f7ff - <rustc_middle::ty::SymbolName as core::fmt::Debug>::fmt::ha51d28018e278c75
  60:     0x7ff890439ddd - <rustc_middle::ty::SymbolName as core::fmt::Debug>::fmt::ha51d28018e278c75
  61:     0x7ff89f3d851a - std::sys::windows::thread::Thread::new::h35832c8baf769397
  62:     0x7ff912a97034 - BaseThreadInitThunk
  63:     0x7ff914882651 - RtlUserThreadStart

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.53.0-nightly (7f4afdf02 2021-04-22) running on x86_64-pc-windows-msvc

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [normalize_generic_arg_after_erasing_regions] normalizing `fn([closure@warp::Server<warp::filter::and_then::AndThen<warp::filter::FilterFn<[closure@warp::filters::method::method_is<[closure@warp::get::{closure#0}]>::{closure#0}]>, fn() -> impl futures::Future {test1}>>::bind_ephemeral<([u8; 4], u16)>::{closure#0}], <warp::hyper::Server<warp::hyper::server::conn::AddrIncoming, warp::hyper::service::make::MakeServiceFn<[closure@warp::Server<warp::filter::and_then::AndThen<warp::filter::FilterFn<[closure@warp::filters::method::method_is<[closure@warp::get::{closure#0}]>::{closure#0}]>, fn() -> impl futures::Future {test1}>>::bind_ephemeral<([u8; 4], u16)>::{closure#1}::{closure#0}]>> as futures::Future>::Output) -> <[closure@warp::Server<warp::filter::and_then::AndThen<warp::filter::FilterFn<[closure@warp::filters::method::method_is<[closure@warp::get::{closure#0}]>::{closure#0}]>, fn() -> impl futures::Future {test1}>>::bind_ephemeral<([u8; 4], u16)>::{closure#0}] as futures_util::fns::FnOnce1<<warp::hyper::Server<warp::hyper::server::conn::AddrIncoming, warp::hyper::service::make::MakeServiceFn<[closure@warp::Server<warp::filter::and_then::AndThen<warp::filter::FilterFn<[closure@warp::filters::method::method_is<[closure@warp::get::{closure#0}]>::{closure#0}]>, fn() -> impl futures::Future {test1}>>::bind_ephemeral<([u8; 4], u16)>::{closure#1}::{closure#0}]>> as futures::Future>::Output>>::Output {<[closure@warp::Server<warp::filter::and_then::AndThen<warp::filter::FilterFn<[closure@warp::filters::method::method_is<[closure@warp::get::{closure#0}]>::{closure#0}]>, fn() -> impl futures::Future {test1}>>::bind_ephemeral<([u8; 4], u16)>::{closure#0}] as futures_util::fns::FnOnce1<<warp::hyper::Server<warp::hyper::server::conn::AddrIncoming, warp::hyper::service::make::MakeServiceFn<[closure@warp::Server<warp::filter::and_then::AndThen<warp::filter::FilterFn<[closure@warp::filters::method::method_is<[closure@warp::get::{closure#0}]>::{closure#0}]>, fn() -> impl futures::Future {test1}>>::bind_ephemeral<([u8; 4], u16)>::{closure#1}::{closure#0}]>> as futures::Future>::Output>>::call_once}`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
```

</p>
</details>