You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#![feature(associated_types)]traitFactory{typeProduct;fncreate(&self) -> <SelfasFactory>::Product;}implFactoryforf64{typeProduct = f64;fncreate(&self) -> f64{*self**self}}impl<A:Factory,B:Factory>Factoryfor(A,B){typeProduct = (<AasFactory>::Product, <BasFactory>::Product);// line 14fncreate(&self) -> (<AasFactory>::Product, <BasFactory>::Product){let(ref a,ref b) = *self;(a.create(), b.create())}}fnmain(){println!("{}",(4.0f64,5.0f64).create());// ^ should print (16, 25)}
Failed to compile with error:
1.rs:14:20: 14:70 error: illegal recursive type; insert an enum or struct in the cycle, if this is desired
1.rs:14 type Product = (<A as Factory>::Product, <B as Factory>::Product);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The way I see it the expansion should be as follows.
Given a HList of type: HCons<int, HCons<int, HNil>> a call to take(S { pred: Z }) should result in solving an obligation for an impl of Take<S<Z>> for HCons<int, HCons<int, HNil>> which incurs a sub obligation to produce an instance of Take<Z> for HCons<int, HNil>.
When checking this we should know Take<_>::R always resolve to an HList (in this case to HNil) and then HCons<int, <T as Take<Z>>::R> should be equivalent to HCons<int, H0: HList> for the representability check. So forall T, H: HList. HCons<T, H> can be represented as HCons { head: T, tail: Box<H> } which looks finite to me.
Activity
jroesch commentedon Dec 22, 2014
@nikomatsakis This seems like a bug to me as well. I just encountered it trying to get this code to compile: https://github.com/jroesch/molten/blob/master/src/hlist.rs#L76.
The way I see it the expansion should be as follows.
Given a HList of type:
HCons<int, HCons<int, HNil>>
a call totake(S { pred: Z })
should result in solving an obligation for an impl ofTake<S<Z>> for HCons<int, HCons<int, HNil>>
which incurs a sub obligation to produce an instance ofTake<Z> for HCons<int, HNil>
.When checking this we should know
Take<_>::R
always resolve to anHList
(in this case toHNil
) and thenHCons<int, <T as Take<Z>>::R>
should be equivalent toHCons<int, H0: HList>
for the representability check. Soforall T, H: HList. HCons<T, H>
can be represented asHCons { head: T, tail: Box<H> }
which looks finite to me.Auto merge of #26481 - nham:test-18655, r=arielb1
Rollup merge of rust-lang#81387 - c410-f3r:tests-tests-tests, r=petro…
Rollup merge of rust-lang#81387 - c410-f3r:tests-tests-tests, r=petro…