-
Notifications
You must be signed in to change notification settings - Fork 11
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
recursive enum testcase #26
base: master
Are you sure you want to change the base?
Conversation
Hrm. ISTM that this ought to work. Sorry for breaking it. I'll look into it. (I have been away, so sorry for the delay.) |
So. I wrote in #19
That turns out to have been wrong. I hadn't considered the recursive case. My apologies. With 0.6.0, there is a workaround:
I think needing that syntax is rather poor. I think it ought to realise that when there are no generics, there is no need for bounds. I'm not sure if doing that would be a breaking change. It would definitely be a breaking change, and maybe even an inadviseable one, for the case where the struct has generic lifetimes. Consider
Where there aren't any generics I think it should be OK? But it would be nice to be sure. |
I think I see two possible behaviours:
I don't think the ad-hoc identifier-scanning approach taken in 0.5.11 and earlier is a great idea, even as a default behaviour. It's rather unpredictable. And each improvement to it is a breaking change. |
Having slept on it, I think I prefer 2, which is basically going back to the default bounds semantics of educe 0.4. It would be nice to provide an option for precise field-based bounds but I don't know what the syntax should be. @magiclen, what do you think? I'm happy to implement either of the options I suggest above. |
Thank you @ijackson this is a difficult problem indeed. Sorry if it's been written somewhere, what's the original idea behind I'd say if there is no obvious solution, may be we can have a special tag like: #[derive(Educe)]
#[educe(Hash(resursive))] that's basically an alias to the old behavior.
It's Hyrum's Law haha! |
I was trying to fix the scheme in 0.5 which basically tried to grep the field types to see which generics ought to get bounds. I think that approach is fundamentally wrong. The "precise bounds" thing gets this exactly right, when the compiler can cope. We basically write
Well, I think in fact it's just me making a mistake. If someone had said "what about recursive structs" I would have realised this would be a breaking change, and probably also thought it was a poor default. So, sorry.
I'm not a huge fan of this syntax suggestion. There's already a workaround: write I think we should take a step back. I think we have the following possible behaviours for bounds:
Of these, I think 5 is incoherent and error-prone ought to not to be offered. For example it can be easily confused by type aliases and can't see into generic field types properly. I think the main question is which of 1-3 ought to be the default. Previously I thought that 3 ("precise" aka field-type-based) bounds was the best default. It works right in almost every situation - except recursive types (and maybe some other weird cases, I guess). But the error is very confusing and tickets we've seen suggest that users don't know that they could fix it by specifying the bounds precisely with the I now think that 1 or 2 ought to be the default. 1 (no bounds by default) has the virtue of simplicity and a complete lack of magic ; and the error, if bounds are needed, is fairly easy to figure out. It is also nice because a main reason for using educe, rather than std, is precisely that we want a derived impl which isn't bounded by the generics. IME many of use sites of educe are for this reason, and certainly the vast majority very happy with the 0.4 "no bounds by default" behaviour. So I suggest going back to "no bounds" by default (option 1). The next question, is what syntax to provide for specifying bounds. The Do we want to provide a syntax for "all bounds"? Do we want to provide a syntax for "make a bound from this field type" or "from all field types"?
|
thank you for your detailed explanation! I agree with 1 or 2 being the default, and between 1&2, I think I'd pick the one being 1) simpler and 2) less surprising. I think |
Thanks for the feedback. I'd be happy to make an MR along those lines. But, I think it would make sense to complete (or reject) the refactoring I'm proposing in #31 first. That work will radically reduce the number of different places that needed to be edited. (The last time I touched this there were 18 almost-identical hunks...) |
This used to work before "Merge branch 'ijackson-precise-bounds'" (2813ba0)
And fails to compile afterwards.