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
Is the restriction on recursive types really necessary?
It makes sense with structs, because recursive structs would mean infinite-sized structs. But with types, it seems unnecessary. After a brief discussion on the Rust IRC, someone told me that this is probably a bug.
Reduced Test Case
traitA<T>{}traitDoesAforB<T>{}// no way to express// struct B<T> where B<T>: A<B<T>>;structB<T:DoesAforB<B<T>>>;fnmain(){}
Output
rec.rs:8:23: 8:27 error: illegal recursive type; insert an enum or struct in the cycle, if this is desired
rec.rs:8 struct B<T: DoesAforB<B<T>>>;
^~~~
The use case I had in mind for this would be having B<X> implementing A<B<X>> for each X, in the crate where X is defined. So it could be specific to Xs, and it would only be possible to instantiate a B<X> if A<B<X>> is implemented.
This is more-or-less a dup of an existing issue I can't find right now. It's an artifact of how we translate bounds, which winds up forcing a DAG structure. It's in the process of being changed.
@anishathalye the reduced test case produces the following error message on stable:
error: parameter `T` is never used [--explain E0392]
--> <anon>:9:10
|>
9 |> struct B<T: DoesAforB<B<T>>>;
|> ^
help: consider removing `T` or using a marker such as `std::marker::PhantomData`
error: aborting due to previous error
If we change the test case so T is actually used, then the example compiles fine. Maybe this can be closed?
Activity
eddyb commentedon Dec 6, 2014
Even if we decide to not allow recursion, this is NOT recursion, it's referring to the same
B<T>, notB<Foo<T>>.anishathalye commentedon Dec 6, 2014
The use case I had in mind for this would be having
B<X>implementingA<B<X>>for eachX, in the crate whereXis defined. So it could be specific toXs, and it would only be possible to instantiate aB<X>ifA<B<X>>is implemented.nikomatsakis commentedon Jan 7, 2015
This is more-or-less a dup of an existing issue I can't find right now. It's an artifact of how we translate bounds, which winds up forcing a DAG structure. It's in the process of being changed.
milibopp commentedon Mar 24, 2015
The following version of the code example in the OP works now:
mrhota commentedon Aug 19, 2016
@anishathalye the reduced test case produces the following error message on stable:
If we change the test case so
Tis actually used, then the example compiles fine. Maybe this can be closed?ping @nikomatsakis
Mark-Simulacrum commentedon May 11, 2017
Marking as E-neestest to permit closing this.
Mark-Simulacrum commentedon May 11, 2017
Also going to unassign @nikomatsakis since I don't think they need to do actively do anything on this issue.
Rollup merge of rust-lang#42734 - MaloJaffre:tests, r=Mark-Simulacrum
Rollup merge of rust-lang#42734 - MaloJaffre:tests, r=Mark-Simulacrum