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

FullfillmentError ICE with const fn and existential type #53092

DutchGhost opened this issue Aug 5, 2018 · 5 comments

FullfillmentError ICE with const fn and existential type #53092

DutchGhost opened this issue Aug 5, 2018 · 5 comments


Copy link

@DutchGhost DutchGhost commented Aug 5, 2018

Again something that is highly unlikely to ever be found in real code, but nonetheless ICE's:

MCVE: #53092 (comment)


const fn transmute<T, U>(t: T) -> U {
    union Transform<TT, UU> {
        t: TT,
        u: UU,
    unsafe { Transform { t }.u }

existential type Foo<F, U>: Fn(F) -> U + Copy;

const BAZR: Foo<u8, ()> = transmute(|x: ()| { x });

fn bar<T, U: From<T>>() -> Foo<T, U> { |x| x.into() }

fn main() {
    let x = BAZR(0);


error: internal compiler error: librustc/traits/codegen/ Encountered errors `[FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<() as std::convert::From<u8>>)),depth=1),Unimplemented)]` resolving bounds after type-checking

thread 'main' panicked at 'Box<Any>', librustc_errors/
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/
   1: std::sys_common::backtrace::print
             at libstd/sys_common/
             at libstd/sys_common/
   2: std::panicking::default_hook::{{closure}}
             at libstd/
   3: std::panicking::default_hook
             at libstd/
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at libstd/
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::span_bug
   8: rustc::session::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::session::opt_span_bug_fmt
  13: rustc::session::span_bug_fmt
  14: rustc::traits::codegen::<impl rustc::infer::InferCtxt<'a, 'gcx, 'tcx>>::drain_fulfillment_cx_or_panic
  15: rustc::ty::context::tls::with_related_context
  16: rustc::traits::codegen::codegen_fulfill_obligation
  17: rustc::ty::query::__query_compute::codegen_fulfill_obligation
  18: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::codegen_fulfill_obligation<'tcx>>::compute
  19: rustc::dep_graph::graph::DepGraph::with_task_impl
  20: rustc::ty::context::tls::with_related_context
  21: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  22: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  23: rustc::ty::instance::Instance::resolve
  24: rustc_mir::monomorphize::collector::visit_fn_use
  25: <rustc_mir::monomorphize::collector::MirNeighborCollector<'a, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_terminator_kind
  26: rustc_mir::monomorphize::collector::collect_items_rec
  27: rustc_mir::monomorphize::collector::collect_items_rec
  28: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}
  29: rustc::util::common::time
  30: rustc_mir::monomorphize::collector::collect_crate_mono_items
  31: rustc::util::common::time
  32: rustc_codegen_llvm::base::collect_and_partition_mono_items
  33: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::collect_and_partition_mono_items<'tcx>>::compute
  34: rustc::dep_graph::graph::DepGraph::with_task_impl
  35: rustc::ty::context::tls::with_related_context
  36: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  37: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  38: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  39: rustc::util::common::time
  40: rustc_driver::driver::phase_4_codegen
  41: rustc_driver::driver::compile_input::{{closure}}
  42: rustc::ty::context::tls::enter_context
  43: <std::thread::local::LocalKey<T>>::with
  44: rustc::ty::context::TyCtxt::create_and_enter
  45: rustc_driver::driver::compile_input
  46: rustc_driver::run_compiler_with_pool
  47: <scoped_tls::ScopedKey<T>>::set
  48: syntax::with_globals
  49: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  50: __rust_maybe_catch_panic
             at libpanic_unwind/
  51: rustc_driver::run
  52: rustc_driver::main
  53: std::rt::lang_start::{{closure}}
  54: std::panicking::try::do_call
             at libstd/
             at libstd/
  55: __rust_maybe_catch_panic
             at libpanic_unwind/
  56: std::rt::lang_start_internal
             at libstd/
             at libstd/
             at libstd/
  57: main
  58: __libc_start_main
  59: <unknown>
query stack during panic:
#0 [codegen_fulfill_obligation] checking if `std::convert::Into` fulfills its obligations
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to previous error

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report:

note: rustc 1.30.0-nightly (3edb355b7 2018-08-03) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -C codegen-units=1 --crate-type bin

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

error: Could not compile `playground`.

To learn more, run the command again with --verbose.


fn bar<T, U: From<T>>() -> Foo<T, U> { |x| x.into() }


fn bar<T, U: From<T>>() -> Foo<T, U> { |x| U::from(x) }

also ICE's but with a different message:

error: internal compiler error: librustc/traits/codegen/ Encountered error `Unimplemented` selecting `Binder(<() as std::convert::From<u8>>)` during codegen`

Removing the Copy from the existential type, gives the same ICE as #53087

@DutchGhost DutchGhost changed the title FullfillmentError with const fn and existential type FullfillmentError ICE with const fn and existential type Aug 5, 2018
@oli-obk oli-obk self-assigned this Jan 25, 2019

This comment has been hidden.


This comment has been hidden.


This comment has been hidden.


This comment has been hidden.

Copy link

@jackh726 jackh726 commented Feb 3, 2021

Much more minimized repro:


type Bug<T, U> = impl Fn(T) -> U + Copy;

const CONST_BUG: Bug<u8, ()> = unsafe { std::mem::transmute(|_: u8| ()) };

fn make_bug<T, U: From<T>>() -> Bug<T, U> {
    |x| x.into()

fn main() {


This is only a type_alias_impl_trait bug, so we can probably remove the other labels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants