Closed
Description
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
Metadata
Metadata
Assignees
Labels
Category: This is a bug.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Medium priority