Custom derives already exist in the form of procedural macros. And that mechanism is far more general then your proposal would allow, I’m not even sure how it would be used to derive any interesting non-marker traits, since reflection is basically non-existent in the trait system — how would Struct allow getting the value of a field, or its name, generically?
@rkruppe Maybe you have missed those lines (with type Tuple similar to what is proposed in 1935):
In some aspect my proposal is not that far from a sort of reflection. Basically a few primitive auto implemented traits that would allow some kind of internal inspection of every type in Rust.
My memory may be faulty, but what are these multiple ad-hoc mechanisms, besides auto traits (impl Tr for …) and Copy.
As far as I know logic for derived implementation of Ord, Eq, Clone, Copy and the likes was directly implemented inside the compiler. But that may have changed. Can anyone confirm or disconfirm?
Leaving aside the questions of whether this proposal can even model Copy (negative bounds seem required for that), […]
I’ve never denied it would need negative bounds. This proposal is strictly prospective and does need other feature to be available to work efficiently.
I would also like to point out that auto traits are using different rules from normal traits, specifically they are using coinductive reasoning instead of inductive reasoning.
This argument looks interesting and I’m completely ready to believe you but to be honest I’m not sure I understand it very well. If I were to implement manually any trait on your type - for example providing some impl PartialEq for List<T> where T : PartialEq - with the obvious field-based implementation, the compiler would need to check if this implementation is legal which looks from my (certainly naive) point of view similar to the infinit regress you’re talking about (the implementation of PartialEq for List<T> is valid if there exist a valid implementation of PartialEq for List<T>). What makes those two cases different? (This is genuine question, not a rethorical one)
There are not specific rules for each primitive trait; there are two different cases in which traits are implemented automatically: auto trait (Send, Sync, UnwindSafe) & Sized.
Copy is also a special trait. To be clear again this discussion concerns more than auto traits.
You propose three new special cases. This does not seem simplifying on the face of it.
@withoutboats If you are counting traits the fact is I propose more than 3 “special cases”. I focused on Tuple, Struct and a bit on Enum but you could also imagine a trait Closure (The nice thing on this one is that it would allow access to the inner state of closures, that are as far as I know inaccessible). But in the end all those traits would have the same purpose: inspecting the types content by projecting them on tuples (so in the end I consider this family of traits just one single special case. Different perspective I guess).
This change is not well-motivated enough for us to devote attention to it over the many other things we want to do. This would be a deep change to our core language for an ambiguous benefit. I don’t think its fruitful to pursue it further (except as an academic exercise, which could be edifying).
I have a real problem of tone here. I have the impression that I’m opposed a sort of brutal condescending refusal: “Our time is too precious for sterile proposals like these. Get out and play alone if you have time to lose”. To be clear I’m not forcing anyone to implement this. I’m not even proposing a pre-RFC. This was just an invitation to explore some ideas. I would have expected more a constructive answer.