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
{{ message }}
Repository navigation
Recursive traits should be allowed when boxing #17893
hello.rs:5:40: 5:49 error: unsupported cyclic reference between types/traits detected [E0391]
hello.rs:5 trait Stream<T>: Future<Option<(T, Box<Stream<T>>)>> {
^~~~~~~~~
hello.rs:5:40: 5:49 help: run `rustc --explain E0391` to see a detailed explanation
note: the cycle begins when computing the supertraits of `Stream`...
note: ...which then again requires computing the supertraits of `Stream`, completing the cycle.
hello.rs:5:40: 5:49 error: unsupported cyclic reference between types/traits detected [E0391]
hello.rs:5 trait Stream<T>: Future<Option<(T, Box<Stream<T>>)>> {
^~~~~~~~~
hello.rs:5:40: 5:49 help: run `rustc --explain E0391` to see a detailed explanation
note: the cycle begins when computing the supertraits of `Stream`...
note: ...which then again requires computing the supertraits of `Stream`, completing the cycle.
error: aborting due to 2 previous errors
error[E0391]: cycle detected when computing the supertraits of `Stream`
--> src/main.rs:5:1
|
5 | trait Stream<T>: Future<Option<(T, Box<Stream<T>>)>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: ...which again requires computing the supertraits of `Stream`, completing the cycle
I would also like to see this.
My use case is a custom Rc implementation with cycle detection, specifically designed for trait objects.
Code would look something like this:
use core::marker::PhantomData;// API:pubstructRc<Dyn: ?Sized + Trace<Dyn>>{ptr_and_stuff:PhantomData<Dyn>,}pubtraitTrace<Dyn:Trace<Dyn> + ?Sized>{/// Give the tracer access to other Rc<Dyn> that we own./// Their `Dyn` must be the same as ours. fntrace(&self,tracer:fn(&Rc<Dyn>));}// user code:traitMyTrait:Trace<dynMyTrait>{}structMyStruct{field:Rc<dynMyTrait>,}implTrace<dynMyTrait>forMyStruct{fntrace(&self,tracer:fn(&Rc<dynMyTrait>)){tracer(&self.field);}}
The hacky workarounds found on stackoverflow sadly don't work.
Could someone comment if this has a chance to get accepted in the future?
Is the problem that dyn Trait doesn't always implement Trait#88904?
Will #107374-Ztrait-solver=next help?
Does this require coinduction?
Activity
aturon commentedon Oct 9, 2014
cc @nikomatsakis
Currently gets the error "error: illegal recursive type; insert an enum or struct in the cycle, if this is desired"
steveklabnik commentedon Feb 2, 2016
Triage: current error:
steveklabnik commentedon Sep 24, 2018
New error:
dimpolo commentedon Jan 26, 2022
I would also like to see this.
My use case is a custom Rc implementation with cycle detection, specifically designed for trait objects.
Code would look something like this:
The hacky workarounds found on stackoverflow sadly don't work.
dimpolo commentedon Sep 18, 2023
Could someone comment if this has a chance to get accepted in the future?
Is the problem that
dyn Traitdoesn't always implementTrait#88904?Will #107374
-Ztrait-solver=nexthelp?Does this require coinduction?
MRE:
Auto merge of rust-lang#17893 - ShoyuVanilla:issue-17871, r=flodiebold