This is an automated archive made by the Lemmit Bot.

The original was posted on /r/rust by /u/ashleigh_dashie on 2024-11-04 16:20:06+00:00.


EDIT: Comments explain really well why my idea is awful.

So, it just occurred to me when putting another derive on my type that trait derives could be just done automatically for all structs where fields satisfy them. This could be done by the compiler whenever a trait method from a trait in the current scope is called, and would remove loads of derive boilerplate.

Are there any real footguns here, in your opinion? To me it seems like this would only improve the language - if you’re relying on not implementing a trait for your type to express some property that’s an actual footgun, an obfuscation of behaviour. Okay, maybe there are some weird cases with Send/Sync but i guess compiler could just not autoderive unsafe - makes sense.

You could have a situation where user implemented method hides a method you expect to get from a trait, but to me it feels that this is just as likely if you’re using some 3rd party type you don’t know by heart. Compiler could warn about method call being conflicted, and you could still call trait method via < as Trait>::

Are there some technical issues with implementing this, and that’s why we have to use derives? Doesn’t feel like it to me, should be straightforward to implement in the compiler.