Open fjarri opened 1 year ago
Thank you for calling this out! I am excited to learn that "Private in public" and "Overflow evaluating requirements" are fixed in rustc.
While "Lifetime deduplication inference is broken" remains broken, I doubt that we could reasonably change the heuristic used by serde_derive. As you noted, sometimes it can be possible to deduplicate some bounds in a purely syntactic way, but I think the same rustc bug can arise for bounds that are behind supertrait bounds not visible in the macro input, or alternatively just look different in syntax despite being identical semantically.
Could you figure out whether there is an issue about that remaining broken case upstream?
As you noted, sometimes it can be possible to deduplicate some bounds in a purely syntactic way, but I think the same rustc bug can arise for bounds that are behind supertrait bounds not visible in the macro input, or alternatively just look different in syntax despite being identical semantically.
That's true, but I feel like in most cases the simple syntactical deduplication will work well enough.
Could you figure out whether there is an issue about that remaining broken case upstream?
Honestly, I wouldn't even know where to start (tried searching for "lifetime deduplication" just in case, but it doesn't seem to be a widely used term). I guess I'll just make one?
So, like other people, I have encountered a problem with automatic derivation of
Serialize
/Deserialize
in a nested generic hierarchy of types, which requires me to write ugly explicit bounds. The heuristic is described inserde_derive::bound::with_bound()
, and sayswhere obviously the struct needs to be bound instead
A: Serialize, Option<&'b B>: Serialize
.If I'm not mistaken, the reasons behind this heuristic are listed in this comment. I tested this on Rust 1.69.
Private in public. This compiles:
Overflow evaluating requirements. This compiles:
Lifetime deduplication inference is broken. Indeed, this does not compile:
But it does compile for this bound:
So, unless I am missing something, adding bounds for every field type instead of every generic parameter would work fine in the first two cases, and in the third one a deduplication may be required (which I think can be performed automatically for most cases - if we can implement a comparison between types that considers two types that only differ in the lifetime labels equal). So switching to the heuristic where bounds are added for every field type would reduce the amount of times one has to override those bounds. Thoughts?