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
Define and enforce standard derives #555
Comments
I think this is a good idea. Interesting idea to use rustsq. I like it. We could enforce a lot of things in CI with that. |
Have we decided on what the standard trait derives should be?
And additionally I can go either ways on |
Regarding I like that list. We should additionally impl I think we should impl |
Agree with @apoelstra and the original @sanket1729 list. Just would like to ask to extend it with #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)] I do paste thisline before each struct and enum and then remove those derives which does not compile (after some investigation of what prevents from derivation and whether this can be changed). I assume this is what Rust API Guidelines call opportunistic derivation of types. Propose to do the same with all types in rust bitcoin, hashes and secp256k1 (+invoices, miniscript etc) For errors this must be always accompanied with Also, guidelines highly recommend to do types |
Send and Sync are automatically implemented by the compiler if appropriate. Manually implementing them is actually unsafe and usually not required unless you are building low-level synchronization primitives like locks.
Agree with I would only vote against |
It is implemented today exactly as you described. Generally seems
Clear, was wrong reading API guidelines - overlooked phrase "automatically by compiler" |
I implemented a proof-of-concept query with qrates that should get us all traits for all types. For example the output for my currently checked-out |
@apoelstra I'd be interested in the rationale behind not implementing |
I'd be careful about implementing too many traits. There are cases where they don't make sense or are harmful. (e.g. There's a reason As an example where I don't see a clear implementation of a trait is A safer approach would be to assign each type a category and then make sure to implement appropriate traits. E.g. identifiers should definitely impl @sgeisler my understanding is that people often want to change the state of iterator (using |
That was always a hard requirement in my mind, I should have written that. I still think that some form of automated reminder is useful to not forget to derive/impl stuff (which often happens to me when I just try to solve a certain problem and later I'm annoyed because I need to patch in some derive). It's probably best to first agree on a common nice-to-have set of traits and then add exceptions to the rule as we need them. CI enforcement in a nice-to-have thing here, but can come at a later point. |
If this is added to CI as informational only (not block merges) then I'd agree. Same for some questionable clippy lints. (Didn't check which are turned on here but I remember facepalming about some ridiculous instances elsewhere.) |
@sgeisler the "no |
Just my 2 cents: I think it makes sense to keep a sort of best-effort list of our target trait support in the CONTRIBUTING.md, do a single pass over all types now and from now on just try to keep the list in mind when adding/accepting new types. But I'd definitely recommend to not just blindly auto-derive where possible or so because often the traits have meaning that is not correctly conveyed by just deriving them. Like Default is indeed a very tricky one in most occasions. |
Not yet closed because of #560 |
31c4983 Fix IRC log record on gnusha.org (Dr Maxim Orlovsky) e1c8e13 Contributing: improving language and style (Dr Maxim Orlovsky) 45dbaa7 Contributing: remove derivation section (Dr Maxim Orlovsky) 313ac7d Contributing: improve formatting section (Dr Maxim Orlovsky) 78d1a82 Contributing guidelines (Dr Maxim Orlovsky) Pull request description: We've being discussing that a `CONTRIBUTING.md` guidelines are needed for some time and I took an effort to propose it. The main text is taken from `rust-lightning` version (with some additions), but it is extended on the topics we were discussing in multiple issues previously: - list of repository maintainers - standard derives - #555 - naming conventions (after Bitcoin Core) - MSRV and 2018 update #510 - code formatting with `rustfmt` #172 Each of these issue-related amendments to the basic (modified) version of rust-lightning contributing guidelines are made with a separate commit. ACKs for top commit: dr-orlovsky: Sorry for disturbing, @RCasatta @sanket1729, but this needs just a review of a single fixup commit in 31c4983 since your last reviews of this PR. We don't want to merge without your ACKs since you did a lot of commenting here before. RCasatta: ACK 31c4983 Kixunil: ACK 31c4983 apoelstra: ACK 31c4983 sanket1729: utACK 31c4983. Looks good Tree-SHA512: 1b15334a4e867070c0b33ba5fbdb55aea90d09879254673cf93c8bea069118b3543289f6f291e085bf2dd90715b913b783bcb9b025b9113079095cf14c220275
Many standard traits can be easily derived but are often forgotten. In #511 the discussion of what to derive arose for
Error
types in particular. We should define a standard set of traits to implement or derive for every struct/enum to make them interoperable with algorithms and data structures from std. Ideally we could enforce that via CI too, either with some heuristic using regex or something fancy like rustql (rust-corpus/rustql#6).The text was updated successfully, but these errors were encountered: