Skip to content

Commit

Permalink
Auto merge of #1217 - Susurrus:rfc_2235, r=gnzlbg
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Feb 5, 2019
2 parents 1f63b26 + e33f760 commit 942f6ae
Show file tree
Hide file tree
Showing 37 changed files with 2,150 additions and 763 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target
Cargo.lock
*~
style
340 changes: 0 additions & 340 deletions Cargo.lock

This file was deleted.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ default = ["use_std"]
use_std = []
align = []
rustc-dep-of-std = ['align', 'rustc-std-workspace-core']
extra_traits = ["align"]

[workspace]
members = ["libc-test"]
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
`PartialEq` can be enabled with the *extra_traits* feature (requires Rust 1.25
or newer):

```toml
[dependencies]
libc = { version = "0.2", features = ["extra_traits"] }
```

## What is libc?

The primary purpose of this crate is to provide all of the definitions necessary
Expand Down
4 changes: 4 additions & 0 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,8 @@ fi
if [ "$(rustc --version | sed -E 's/^rustc 1\.([0-9]*)\..*/\1/')" -ge 25 ]; then
cargo test $opt --features align --manifest-path libc-test/Cargo.toml --target "${TARGET}"
fi
# Test the `extra_traits` feature if this is building on Rust >= 1.25
if [ "$(rustc --version | sed -E 's/^rustc 1\.([0-9]*)\..*/\1/')" -ge 25 ]; then
cargo test $opt --features extra_traits --manifest-path libc-test/Cargo.toml --target "${TARGET}"
fi
exec cargo test $opt --manifest-path libc-test/Cargo.toml --target "${TARGET}"
1 change: 1 addition & 0 deletions libc-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ctest = "0.2.8"
default = [ "use_std" ]
use_std = [ "libc/use_std" ]
align = [ "libc/align" ]
extra_traits = [ "libc/extra_traits" ]

[[test]]
name = "main"
Expand Down
Loading

0 comments on commit 942f6ae

Please sign in to comment.