-
Notifications
You must be signed in to change notification settings - Fork 1k
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
RFC 2235 - Implement PartialEq,Eq,Hash,Debug for all types #1217
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Cargo.toml
Outdated
@@ -27,6 +27,7 @@ default = ["use_std"] | |||
use_std = [] | |||
align = [] | |||
rustc-dep-of-std = ['align', 'rustc-std-workspace-core'] | |||
extra_traits = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to start by using more fine grained features here (e.g. traits_eq
), and having an extra_traits
feature that enables them all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I worry about the extra maintainability cost of the structs for which the traits cannot be derived automatically (because they contain arrays with more than 32 elements).
Note: the style check is failing.
I think so. |
I'd prefer to not implement it like this. When we talk about maintainability costs, having more features is harder than less features. The RFC also had discussion about this, but I'd like to find out more about why it can't be done as the single trait as I've already implemented it before changing this to individual features.
Do you still have this concern after seeing the implementation? I'm uncertain what the maintainability cost will be that you're concerned about. There isn't much change to types after they're added to
I did this, though looking at the code I didn't see any types I manually implemented this for that would actually benefit from this. I still think it's the right call, as it may help in structs that haven't been added yet though. So I've completed implementing everything here, though there are some open questions on what to do for the fields that I skipped in my manual implementations. I'll see if they're trivial to implement manually or I'll ask if we can set guidelines such that some fields can be skipped to make things easier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM. Thanks!
@bors: r+
Oh, I see that the documentation build bots are still failing. Could you fix those? This error sounds familiar: cc @QuietMisdreavus
|
It looks like the Lines 16 to 17 in fb2b3da
Maybe some kind of import for |
Actually, after digging into it, why are those doc builders still going if libc's docs are going to be hosted on docs.rs (which doesn't use |
That's a good question. I'd expect that |
I also wanted to ask about the |
I've also been thinking that we should probably have a test that checks that each type has the right extra traits. This will ensure any manually-implemented types won't miss traits they should have. But I don't know how to start that implementation; any ideas anyone? |
@Susurrus don't worry about the update to the
IMO the right way to do this is via a clippy lint. That is, we would have (or add) a lint to clippy, e.g., #![cfg_attr(feature = "cargo-clippy", deny(missing_debug_impl_on_public_items))] This lint will error if a public item does not implement #[cfg_attr(feature = "cargo-clippy", allow(missing_debug_impl_on_public_items))]
struct LookMaNoDebug; For every trait, we would need such a lint. You can open an issue about this in clippy upstream and cite this comment as motivation. Implementing such a lint is not hard, I can try to mentor you if you want, but clippy maintainers have a quick turnaround time and if you are in the Discord clippy channel they can tell you which existing lint you can base yours on to get it done quickly. FYI there is prior art of doing this. For example, in EDIT: one issue with this lint is that we would need to run clippy for all targets passing it the appropriate |
☔ The latest upstream changes (presumably #1228) made this pull request unmergeable. Please resolve the merge conflicts. |
@gnzlbg Awesome idea using Clippy, didn't come to mind for me, but it makes a lot of sense. I've gone through Clippy and found the following:
So I've enabled some more lints and fixed some types that broke because of that as you'll see in the latest commits. |
wrong button... |
This isn't ready for merging yet. When it is, I'll remove the WIP from the title of the PR. To catch everyone up on where this stands:
|
I would like some clarity on |
That is an artifact of when a |
This was an artifact from when a git dependency on ctest was used. This is no longer the case, so removing it to simplify future PRs.
Removed |
This was not compile-tested on all platforms, but instead all `pub enum` types had a `Debug` impl derived for them.
This is used for running style checks on the libc codebase but shouldn't be committed, so adding it to the .gitignore file.
None of those failures seem related to my code, seem like CI problems. I figured out how to fix the problem I was talking about, so I think this is all ready for a merge. |
@@ -44,6 +44,16 @@ activate the *align* feature. This requires Rust 1.25 or newer: | |||
libc = { version = "0.2", features = ["align"] } | |||
``` | |||
|
|||
All structs implemented by the libc crate have the `Copy` and `Clone` traits | |||
implemented for them. The additional traits of `Debug, `Eq`, `Hash`, and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there's a missing backtick after Debug.
I'd say, don't derive Hash for this, and open an issue to discuss what to do. No need to block this PR on that. |
@gnzlbg I resolved the issue by using |
Note that all failures in CI here were sporadic and things should work if someone goes in and re-runs the failures. |
So this is pretty much ready, just needs someone to poke at CI for me as we should be all good here. |
@bors: r+ |
📌 Commit e33f760 has been approved by |
RFC 2235 - Implement PartialEq,Eq,Hash,Debug for all types First pass at implementing [RFC2235](https://github.com/rust-lang/rfcs/blob/master/text/2235-libc-struct-traits.md). I just started with `PartialEq`/`Eq` and tested locally on my x64 Linux system. Definitely going to run into other types for other platforms that need this treatment, but thought I'd start small. Open question is whether this should also rely on the `align` feature, which should improve which types can be auto-derived versus manually implemented (as it removed a lot of odd-sized padding arrays). My first pass here doesn't do that, but I might test it out to see if it does simplify quite a few structs. I think it might also be nice to have as it makes it easier for contributors to add new structs. Part of rust-lang/rust#57715
☀️ Test successful - checks-cirrus, checks-travis, status-appveyor |
just to point that targets without CI are a bit broken now (openbsd in mind). I will try to take a look |
First pass at implementing RFC2235. I just started with
PartialEq
/Eq
and tested locally on my x64 Linux system. Definitely going to run into other types for other platforms that need this treatment, but thought I'd start small.Open question is whether this should also rely on the
align
feature, which should improve which types can be auto-derived versus manually implemented (as it removed a lot of odd-sized padding arrays). My first pass here doesn't do that, but I might test it out to see if it does simplify quite a few structs. I think it might also be nice to have as it makes it easier for contributors to add new structs.Part of rust-lang/rust#57715