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

Exception for cyclic-safe traits #29826

Closed
WildCryptoFox opened this issue Nov 14, 2015 · 3 comments
Closed

Exception for cyclic-safe traits #29826

WildCryptoFox opened this issue Nov 14, 2015 · 3 comments

Comments

@WildCryptoFox
Copy link
Contributor

Thy cyclic supertrait lint and super-trait tracing code should have an exception to allow for cyclic-safe traits.

https://play.rust-lang.org/?gist=cc794942ed0663d530d8&version=nightly

A trait definition like this is currently invalid.

trait Mode<M>: Mode<A> { type Return; }

Instead of being invalid, this should cut the recursion at the point that M == RequiredMode.

Any type that implements Mode<B> must also implement Mode<A> and when selecting specific traits with <T as Trait>, the exact trait should be respected.

<T as Mode<B>>::Return // B
<T as Mode<A>>::Return // A
<<T as Mode<B>> as Mode<A>>::Return // A

As demonstrated in #12511, I would also say that trait T: T {} should be the identity of T, and consequently be the identity of the exception to permit cyclic-safe types.

Cyclic safe traits

trait Trait: Trait { ... } // Trait == Trait, stop recurring // lint redundant trait?
trait Mode<M>: Mode<A> { ... } // When M == A, stop recurring

Cyclic unsafe traits

trait A: B { ... }
trait B: A { ... } 
@eefriedman
Copy link
Contributor

In theory, there isn't any reason we can't support trait A: B { ... } trait B: A { ... }. We can reason about the cycle the same way we can for trait A: A.

@WildCryptoFox
Copy link
Contributor Author

@eefriedman True but that would require understanding the known state, instead of just with the exact trait definition. I think that would require a little more work, but indeed, doable.

@arielb1
Copy link
Contributor

arielb1 commented Nov 14, 2015

@james-darkfox

It was an intentional design decision not to allow for cyclic traits. If you desire to change it, you should post an issue at rust-lang/rfcs.

@arielb1 arielb1 closed this as completed Nov 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants