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: Failed to unify obligation #43623

Closed
PieterPenninckx opened this issue Aug 3, 2017 · 4 comments · Fixed by #63397
Closed

ICE: Failed to unify obligation #43623

PieterPenninckx opened this issue Aug 3, 2017 · 4 comments · Fixed by #63397
Assignees
Labels
C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority

Comments

@PieterPenninckx
Copy link
Contributor

The compiler ices with error "Failed to unify obligation" when I try to compile the following code:

trait StreamingIterator<'a> {
	type Item : 'a;
	fn next(&'a mut self) -> Option<Self::Item>;
	fn map<F>(self, f: F) -> StreamingIterMap<Self, F> 
	where Self: Sized
	{
		StreamingIterMap{iter: self, f: f}
	}
}

struct StreamingIterMap<I, F>
{
	iter: I,
	f: F
}

impl<'b, I, F, T> StreamingIterator<'b> for StreamingIterMap<I, F>
where
	I: for<'a:'b> StreamingIterator<'a>,
	F: for<'a:'b> Fn(<I as StreamingIterator<'a>>::Item) -> T,
	T: 'b,
{
	type Item = T;
	fn next(&mut self) -> Option<T> {
		self.iter.next().map(&self.f)
	}
}

struct StreamingCounter {
	index: usize
}

impl<'a> StreamingIterator<'a> for StreamingCounter  {
	type Item = &'a usize;
	fn next(&'a mut self) -> Option<&'a usize> {
		self.index += 1;
		Some(&self.index)
	}
}

fn main() {
	let mut svi = StreamingCounter{index: 0}
		.map(|u| Some(u));
	if let Some(ref i) = svi.next() {
		println!("{}", i);
	}
}

I get the following error:

error: internal compiler error: /checkout/src/librustc/traits/project.rs:1230: Failed to unify obligation `Obligation(predicate=ProjectionTy { trait_ref: <[[email protected]:43:8: 43:19] as std::ops::FnOnce<(<StreamingCounter as StreamingIterator<'a>>::Item,)>>, item_def_id: DefId { krate: CrateNum(2), node: DefIndex(895) => core/ce488d1::ops[0]::FnOnce[0]::Output[0] } },depth=0)` with poly_projection `Binder(ProjectionPredicate(ProjectionTy { trait_ref: <[[email protected]:43:8: 43:19] as std::ops::FnOnce<(&usize,)>>, item_def_id: DefId { krate: CrateNum(2), node: DefIndex(895) => core/ce488d1::ops[0]::FnOnce[0]::Output[0] } }, std::option::Option<_>))`: Sorts(ExpectedFound { expected: &usize, found: <StreamingCounter as StreamingIterator<'a>>::Item })
  --> test.rs:44:27
   |
44 | 	if let Some(ref i) = svi.next() {
   | 	                         ^^^^

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:428
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Meta

rustc --version --verbose:

rustc 1.19.0 (0ade33941 2017-07-17)
binary: rustc
commit-hash: 0ade339411587887bf01bcfa2e9ae4414c8900d4
commit-date: 2017-07-17
host: i686-unknown-linux-gnu
release: 1.19.0
LLVM version: 4.0

Backtrace:

   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:60
             at /checkout/src/libstd/panicking.rs:355
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:365
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:549
   5: std::panicking::begin_panic
   6: rustc_errors::Handler::span_bug
   7: rustc::session::opt_span_bug_fmt::{{closure}}
   8: rustc::session::opt_span_bug_fmt
   9: rustc::session::span_bug_fmt
  10: rustc::traits::project::confirm_param_env_candidate
  11: rustc::traits::project::confirm_callable_candidate
  12: rustc::traits::project::confirm_closure_candidate
  13: rustc::traits::project::confirm_candidate
  14: rustc::traits::project::opt_normalize_projection_type
  15: rustc::traits::project::poly_project_and_unify_type::{{closure}}
  16: rustc::traits::project::poly_project_and_unify_type
  17: rustc::traits::select::SelectionContext::evaluate_predicate_recursively
  18: rustc::traits::select::SelectionContext::evaluate_obligation
  19: <core::iter::Filter<I, P> as core::iter::iterator::Iterator>::next
  20: rustc_typeck::check::method::probe::ProbeContext::consider_candidates
  21: rustc_typeck::check::method::probe::ProbeContext::pick_method
  22: rustc_typeck::check::method::probe::ProbeContext::pick_core
  23: rustc_typeck::check::method::probe::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::probe_for_name
  24: rustc_typeck::check::FnCtxt::check_method_call
  25: rustc_typeck::check::FnCtxt::check_expr_kind
  26: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref
  27: rustc_typeck::check::FnCtxt::check_expr_kind
  28: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref
  29: rustc_typeck::check::FnCtxt::check_block_with_expected::{{closure}}
  30: rustc_typeck::check::FnCtxt::check_block_with_expected
  31: rustc_typeck::check::FnCtxt::check_expr_kind
  32: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref
  33: rustc_typeck::check::FnCtxt::check_return_expr
  34: rustc_typeck::check::check_fn
  35: rustc_typeck::check::typeck_tables_of::{{closure}}
  36: rustc_typeck::check::typeck_tables_of
  37: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::try_get
  38: rustc::ty::maps::TyCtxtAt::typeck_tables_of
  39: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_tables_of
  40: rustc_typeck::check::typeck_item_bodies
  41: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::try_get
  42: rustc::ty::maps::TyCtxtAt::typeck_item_bodies
  43: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_item_bodies
  44: rustc_typeck::check_crate
  45: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}
  46: rustc_driver::driver::phase_3_run_analysis_passes
  47: rustc_driver::driver::compile_input
  48: rustc_driver::run_compiler
@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Aug 3, 2017
@arielb1 arielb1 self-assigned this Nov 23, 2017
@arielb1
Copy link
Contributor

arielb1 commented Nov 30, 2017

Another version:

struct A;
struct B;

trait Foo<'a> {
  type Bar;
}

impl<'a> Foo<'a> for B {
  type Bar = A;
}

trait Bar: for<'a> Foo<'a> {
  fn f<F: for<'a> FnOnce(<Self as Foo<'a>>::Bar)>(&mut self, f: F) {}
}

impl Bar for B {}

fn main() {
  B.f(drop);
}

@michaelwoerister
Copy link
Member

triage: p-medium

@michaelwoerister michaelwoerister added the P-medium Medium priority label Nov 30, 2017
@RustyYato
Copy link
Contributor

RustyYato commented Apr 16, 2019

minimal version

pub trait Trait<'a> {
    type Assoc;
}

pub struct Type;

impl<'a> Trait<'a> for Type {
    type Assoc = ();
}

pub fn break_me<T, F>(f: F)
where T: for<'b> Trait<'b>,
      F: for<'b> FnMut(<T as Trait<'b>>::Assoc) {
    break_me::<Type, fn(_)>;
}

Note that if you pass in the closure |_| () to break_me::<Type, _> it doesn't ICE the compiler when I used cargo check, bud did ICE the compiler when I used cargo build/cargo run.

i.e.

pub trait Trait<'a> {
    type Assoc;
}

pub struct Type;

impl<'a> Trait<'a> for Type {
    type Assoc = ();
}

pub fn break_me<T, F>(f: F)
where T: for<'b> Trait<'b>,
      F: for<'b> FnMut(<T as Trait<'b>>::Assoc) {
    break_me::<Type, _>(|_| ()); // this is fine
}

@jakubadamw
Copy link
Contributor

jakubadamw commented Jul 14, 2019

@michaelwoerister, none of the programs provided seem to ICE with the latest nightly.

@estebank estebank added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. labels Aug 5, 2019
Centril added a commit to Centril/rust that referenced this issue Aug 9, 2019
Centril added a commit to Centril/rust that referenced this issue Aug 9, 2019
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. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants