-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
RFC: make default comparisons as deep as a clone #5767
Comments
I think at least removing the overloaded operators that can recurse forever should be done soon, before it's too painful. |
This sounds reasonable at first, but I'm not sure if I agree with this. It seems to rule out very legitimate use cases. In the borrow checker, for example, we build up little trees representing loan paths. I use Maybe I'm too blase about infinite loops, but I kind of feel like cycles in eq are....not our problem. You can always implement your own version of Eq for types that may contain cyclic references, nobody forced you to derive it. |
@nikomatsakis: well, we could do what python does and figure out a way to keep a table of pointers in TLS while recursing. In a situation where it's easily provable (via |
Isn't this only an issue for |
@nikomatsakis: it's an issue for @ too because you can put a non-Const thing like |
Yes, I was thinking that my logic was flawed. However, if we just don't define Eq for |
@nikomatsakis: we could potentially just define |
Yes. I'd be fine with that as well. If we updated the coherence check as I'm contemplating doing, this would also mean that end users can define Eq for @t where T is non-Const types as they choose. |
Closing this RFC, I think we've come to a better solution of only providing default impls on types known to be non-cyclic. |
…nsch Panic multiple args changelog: Fixes bug with `panic` lint reported in rust-lang#5767. I also did the same changes to the lints for `todo`, `unimplemented` and `unreachable`, so those lints should now also detect calls to those macros with a message.
Traversing @ will recurse forever if there's a cycle. It would be more consistent to use owned trees as the building block for everything, and avoid just having a special case for Clone. There shouldn't be a default Ord/TotalOrd for @t at all imo, just Eq/TotalEq for identity comparison or no default impl.
A different form of equality is still easy to implement, you just wouldn't be able to derive deep equality and shoot yourself in the foot as easily.
The text was updated successfully, but these errors were encountered: