-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Deref to type that is also a Receiver to the original type creates an infinite cycle #139394
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
Comments
This is not a bug. This produces a receiver chain that goes |
@compiler-errors I see how that's an infinite chain, but I don't see how it's an infinite set. There are only two types. Are you saying it's the interaction with autoref that produces an infinite set of types? |
Autoderef doesn't deduplicate infinite chains of types if they have closed cycles. This could be hacked around, but I'd probably discourage it, since this would be problematic, for example, as soon as we had things like type and lifetime variables in the types, since it's pretty easy to construct a chain of types that differ only by inference variables which are yet unresolved. |
All autoderef does is repeatedly apply |
Ok, thanks for answering my questions! To summarize, it would be difficult to do cycle detection because of the possible presence of type variables. Maybe some kind of canonicalization could work if we had to solve this. But we don't really: The Deref impl is a hack to simulate a form of custom autoref, which could be modeled in a more first-class way, albeit only with new language features. |
Let's say I define a transparent receiver type like this:
And then a type which allows "viewing" itself as a
&CRef<T>
when what you have is a&T
:Then given this:
I expect
flag.get()
to mean something likebut instead I got
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=e3e560589bf664d37a489d798f41cca5
It's possible this is somehow correct and there's no way to do what I'm trying to do, but if it is I don't see why.
The text was updated successfully, but these errors were encountered: