Skip to content
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

Remove extra traits #3692

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Raw FFI bindings to platform libraries like libc.
rust-version = "1.71.0"

[package.metadata.docs.rs]
features = ["const-extern-fn", "extra_traits"]
features = ["const-extern-fn"]
default-target = "x86_64-unknown-linux-gnu"
targets = [
"aarch64-apple-darwin",
Expand Down Expand Up @@ -138,7 +138,6 @@ default = ["std"]
std = []
align = []
rustc-dep-of-std = ['align', 'rustc-std-workspace-core']
extra_traits = []
const-extern-fn = []

[workspace]
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ libc = "0.2"
feature to remove this dependency and be able to use `libc` in `#![no_std]`
crates.

* `extra_traits`: all `struct`s implemented in `libc` are `Copy` and `Clone`.
This feature derives `Debug`, `Eq`, `Hash`, and `PartialEq`.

* `const-extern-fn`: Changes some `extern fn`s into `const extern fn`s.
If you use Rust >= 1.62, this feature is implicitly enabled.
Otherwise it requires a nightly rustc.
Expand Down
20 changes: 0 additions & 20 deletions ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@ test_target() {
-Z build-std=core,alloc -vv --target "${TARGET}"
fi

# Test that libc builds with the `extra_traits` feature
if [ "${NO_STD}" != "1" ]; then
cargo "+${RUST}" "${BUILD_CMD}" -vv --no-default-features --target "${TARGET}" \
--features extra_traits
else
RUSTFLAGS="-A improper_ctypes_definitions" cargo "+${RUST}" "${BUILD_CMD}" \
-Z build-std=core,alloc -vv --no-default-features \
--target "${TARGET}" --features extra_traits
fi

# Test the 'const-extern-fn' feature on nightly
if [ "${RUST}" = "nightly" ]; then
if [ "${NO_STD}" != "1" ]; then
Expand All @@ -77,16 +67,6 @@ test_target() {
--target "${TARGET}" --features const-extern-fn
fi
fi

# Also test that it builds with `extra_traits` and default features:
if [ "$NO_STD" != "1" ]; then
cargo "+${RUST}" "${BUILD_CMD}" -vv --target "${TARGET}" \
--features extra_traits
else
RUSTFLAGS="-A improper_ctypes_definitions" cargo "+${RUST}" "${BUILD_CMD}" \
-Z build-std=core,alloc -vv --target "${TARGET}" \
--features extra_traits
fi
}

RUST_LINUX_TARGETS="\
Expand Down
4 changes: 2 additions & 2 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ if [ "$TARGET" = "s390x-unknown-linux-gnu" ]; then
continue
fi
elif [ "$passed" = "2" ]; then
if cargo test --features extra_traits --manifest-path libc-test/Cargo.toml --target "${TARGET}" ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"}; then
if cargo test --manifest-path libc-test/Cargo.toml --target "${TARGET}" ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"}; then
break
fi
fi
Expand All @@ -114,6 +114,6 @@ else

cargo test --manifest-path libc-test/Cargo.toml --target "${TARGET}" ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"}

RUST_BACKTRACE=1 cargo test --features extra_traits --manifest-path libc-test/Cargo.toml \
RUST_BACKTRACE=1 cargo test --manifest-path libc-test/Cargo.toml \
--target "${TARGET}" ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"}
fi
8 changes: 0 additions & 8 deletions ci/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ enum State {

fn check_style(file: &str, path: &Path, err: &mut Errors) {
let mut state = State::Start;
let mut s_macros = 0;
let mut f_macros = 0;
let mut in_impl = false;

Expand Down Expand Up @@ -140,9 +139,6 @@ fn check_style(file: &str, path: &Path, err: &mut Errors) {
} else if line.starts_with("type ") && !in_impl {
State::Typedefs
} else if line.starts_with("s! {") {
s_macros += 1;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to allow multiple s! macros in one module because the s_no_extra_traits! macro no longer exists.

State::Structs
} else if line.starts_with("s_no_extra_traits! {") {
// multiple macros of this type are allowed
State::Structs
} else if line.starts_with("s_paren! {") {
Expand Down Expand Up @@ -175,10 +171,6 @@ fn check_style(file: &str, path: &Path, err: &mut Errors) {
f_macros += 1;
err.error(path, i, "multiple f! macros in one module");
}
if s_macros == 2 {
s_macros += 1;
err.error(path, i, "multiple s! macros in one module");
}

state = line_state;
}
Expand Down
1 change: 0 additions & 1 deletion libc-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ ctest2 = "0.4.3"
default = ["std"]
std = ["libc/std"]
align = ["libc/align"]
extra_traits = ["libc/extra_traits"]

[[test]]
name = "main"
Expand Down
72 changes: 0 additions & 72 deletions src/fuchsia/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ macro_rules! expand_align {
pub struct pthread_condattr_t {
size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T],
}
}

s_no_extra_traits! {
#[cfg_attr(all(target_pointer_width = "32",
any(target_arch = "arm",
target_arch = "x86_64")),
Expand Down Expand Up @@ -68,75 +66,5 @@ macro_rules! expand_align {
size: [u8; ::__SIZEOF_PTHREAD_COND_T],
}
}

cfg_if! {
if #[cfg(feature = "extra_traits")] {
impl PartialEq for pthread_cond_t {
fn eq(&self, other: &pthread_cond_t) -> bool {
self.size
.iter()
.zip(other.size.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for pthread_cond_t {}
impl ::fmt::Debug for pthread_cond_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("pthread_cond_t")
// FIXME: .field("size", &self.size)
.finish()
}
}
impl ::hash::Hash for pthread_cond_t {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.size.hash(state);
}
}

impl PartialEq for pthread_mutex_t {
fn eq(&self, other: &pthread_mutex_t) -> bool {
self.size
.iter()
.zip(other.size.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for pthread_mutex_t {}
impl ::fmt::Debug for pthread_mutex_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("pthread_mutex_t")
// FIXME: .field("size", &self.size)
.finish()
}
}
impl ::hash::Hash for pthread_mutex_t {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.size.hash(state);
}
}

impl PartialEq for pthread_rwlock_t {
fn eq(&self, other: &pthread_rwlock_t) -> bool {
self.size
.iter()
.zip(other.size.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for pthread_rwlock_t {}
impl ::fmt::Debug for pthread_rwlock_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("pthread_rwlock_t")
// FIXME: .field("size", &self.size)
.finish()
}
}
impl ::hash::Hash for pthread_rwlock_t {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.size.hash(state);
}
}
}
}
};
}
Loading