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

ICE OutputTypeParameterMismatch #88042

Closed
HellButcher opened this issue Aug 15, 2021 · 1 comment
Closed

ICE OutputTypeParameterMismatch #88042

HellButcher opened this issue Aug 15, 2021 · 1 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.

Comments

@HellButcher
Copy link

Code

use std::{cell::{Ref, RefCell}, marker::PhantomData};

trait Query<'a> {
  type Fetch: for<'b> Fetch<'a, 'b>;
}
trait Fetch<'a,'b>{
  type Item: 'b;
  fn borrow(source: &'a A) -> Self;
  fn get(&'b self, index: usize) -> Self::Item;
}

struct A(RefCell<Vec<u32>>);
struct ARef<'a>(Ref<'a, Vec<u32>>);

impl<'a,'b> Fetch<'a,'b> for ARef<'a> {
  type Item = &'b u32;
  fn borrow(source: &'a A) -> Self {
    ARef(source.0.borrow())
  }
  fn get(&'b self, index: usize) -> Self::Item {
    &self.0[index]
  }
}

impl<'a> Query<'a> for &'_ u32 {
  type Fetch = ARef<'a>;
}

struct Qry<Q>(PhantomData<Q>);

impl<'a, Q> Qry<Q>
  where Q: Query<'a>
{
  fn new() -> Self { Self(PhantomData) }
  fn with_fn<F,R>(&self, source: &'a A, index: usize, f: F) -> R
    where for<'b> F: FnOnce(<Q::Fetch as Fetch<'a, 'b>>::Item) -> R
  {
    let b = Q::Fetch::borrow(source);
    let item = b.get(index);
    f(item)
  }
}

pub fn test() {
  let a = A(RefCell::new(vec![1,2,3]));
  let qry = Qry::<&u32>::new();
  assert_eq!(9, qry.with_fn(&a, 2, |v| *v * 3));
}

Meta

rustc --version --verbose:

rustc 1.54.0 (a178d0322 2021-07-26)
binary: rustc
commit-hash: a178d0322ce20e33eac124758e837cbd80a6f633
commit-date: 2021-07-26
host: x86_64-unknown-linux-gnu
release: 1.54.0
LLVM version: 12.0.1

Error output

error: internal compiler error: compiler/rustc_trait_selection/src/traits/codegen.rs:78:17: Encountered error `OutputTypeParameterMismatch(Binder(<[closure@crates/ice/src/lib.rs:47:36: 47:46] as std::ops::FnOnce<(<ARef as Fetch<'_, '_>>::Item,)>>, [Region(BrAnon(0))]), Binder(<[closure@crates/ice/src/lib.rs:47:36: 47:46] as std::ops::FnOnce<(&u32,)>>, []), Sorts(ExpectedFound { expected: &u32, found: <ARef as Fetch<'_, '_>>::Item }))` selecting `Binder(<[closure@crates/ice/src/lib.rs:47:36: 47:46] as std::ops::FnOnce<(&u32,)>>, [])` during codegen

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1007:9
stack backtrace:
[...]

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.54.0 (a178d0322 2021-07-26) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental

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

query stack during panic:
#0 [codegen_fulfill_obligation] checking if `std::ops::FnOnce` fulfills its obligations
#1 [resolve_instance] resolving instance `<[closure@crates/ice/src/lib.rs:48:36: 48:46] as std::ops::FnOnce<(&u32,)>>::call_once`
#2 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to previous error
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1007:9
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_infer::infer::InferCtxtBuilder::enter
   8: rustc_trait_selection::traits::codegen::codegen_fulfill_obligation
   9: rustc_query_impl::<impl rustc_query_system::query::config::QueryAccessors<rustc_query_impl::plumbing::QueryCtxt> for rustc_query_impl::queries::codegen_fulfill_obligation>::compute
  10: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  11: rustc_data_structures::stack::ensure_sufficient_stack
  12: rustc_query_system::query::plumbing::get_query_impl
  13: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::codegen_fulfill_obligation
  14: rustc_ty_utils::instance::inner_resolve_instance
  15: rustc_ty_utils::instance::resolve_instance
  16: rustc_query_impl::<impl rustc_query_system::query::config::QueryAccessors<rustc_query_impl::plumbing::QueryCtxt> for rustc_query_impl::queries::resolve_instance>::compute
  17: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  18: rustc_data_structures::stack::ensure_sufficient_stack
  19: rustc_query_system::query::plumbing::get_query_impl
  20: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::resolve_instance
  21: rustc_middle::ty::instance::Instance::resolve_opt_const_arg
  22: rustc_middle::ty::instance::Instance::resolve
  23: <rustc_mir::monomorphize::collector::MirNeighborCollector as rustc_middle::mir::visit::Visitor>::visit_terminator
  24: rustc_mir::monomorphize::collector::collect_neighbours
  25: rustc_mir::monomorphize::collector::collect_items_rec
  26: rustc_mir::monomorphize::collector::collect_items_rec
  27: rustc_mir::monomorphize::collector::collect_items_rec
  28: rustc_mir::monomorphize::collector::collect_items_rec
  29: rustc_session::utils::<impl rustc_session::session::Session>::time
  30: rustc_mir::monomorphize::collector::collect_crate_mono_items
  31: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
  32: rustc_query_impl::<impl rustc_query_system::query::config::QueryAccessors<rustc_query_impl::plumbing::QueryCtxt> for rustc_query_impl::queries::collect_and_partition_mono_items>::compute
  33: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  34: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  35: rustc_data_structures::stack::ensure_sufficient_stack
  36: rustc_query_system::query::plumbing::force_query_with_job
  37: rustc_query_system::query::plumbing::get_query_impl
  38: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::collect_and_partition_mono_items
  39: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  40: rustc_interface::passes::QueryContext::enter
  41: rustc_interface::queries::Queries::ongoing_codegen
  42: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  43: rustc_span::with_source_map
  44: rustc_interface::interface::create_compiler_and_run
  45: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@HellButcher HellButcher 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 Aug 15, 2021
@jackh726
Copy link
Member

Closing as duplicate of #62529 (see #85499 for likely fix)

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

No branches or pull requests

2 participants