Skip to content

Commit 98d9b8c

Browse files
Require rust >= 1.19 and drop libc_union conditional
This is mostly taken from Josh's work at <rust-lang#2845>. I just updated to remove all new uses of `libc_union` introduced since then. Co-authored-by: Josh Triplett <josh@joshtriplett.org>
1 parent 3744c51 commit 98d9b8c

File tree

22 files changed

+611
-951
lines changed

22 files changed

+611
-951
lines changed

build.rs

-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
2828
"libc_ptr_addr_of",
2929
"libc_thread_local",
3030
"libc_underscore_const_names",
31-
"libc_union",
3231
"libc_ctest",
3332
];
3433

@@ -98,11 +97,6 @@ fn main() {
9897
set_cfg("libc_deny_warnings");
9998
}
10099

101-
// Rust >= 1.19 supports unions:
102-
if rustc_minor_ver >= 19 || rustc_dep_of_std {
103-
set_cfg("libc_union");
104-
}
105-
106100
// Rust >= 1.24 supports const mem::size_of:
107101
if rustc_minor_ver >= 24 || rustc_dep_of_std {
108102
set_cfg("libc_const_size_of");

libc-test/build.rs

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ fn do_ctest() {
6868
fn ctest_cfg() -> ctest::TestGenerator {
6969
let mut cfg = ctest::TestGenerator::new();
7070
let libc_cfgs = [
71-
"libc_union",
7271
"libc_const_size_of",
7372
"libc_align",
7473
"libc_core_cvoid",

src/macros.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,15 @@ macro_rules! s_no_extra_traits {
9090
s_no_extra_traits!(it: $(#[$attr])* pub $t $i { $($field)* });
9191
)*);
9292
(it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => (
93-
cfg_if! {
94-
if #[cfg(libc_union)] {
95-
__item! {
96-
#[repr(C)]
97-
$(#[$attr])*
98-
pub union $i { $($field)* }
99-
}
93+
__item! {
94+
#[repr(C)]
95+
$(#[$attr])*
96+
pub union $i { $($field)* }
97+
}
10098

101-
impl ::Copy for $i {}
102-
impl ::Clone for $i {
103-
fn clone(&self) -> $i { *self }
104-
}
105-
}
99+
impl ::Copy for $i {}
100+
impl ::Clone for $i {
101+
fn clone(&self) -> $i { *self }
106102
}
107103
);
108104
(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (

src/unix/aix/mod.rs

+15-39
Original file line numberDiff line numberDiff line change
@@ -534,20 +534,17 @@ s! {
534534
}
535535

536536
s_no_extra_traits! {
537-
#[cfg(libc_union)]
538537
pub union __sigaction_sa_union {
539538
pub __su_handler: extern fn(c: ::c_int),
540539
pub __su_sigaction: extern fn(c: ::c_int, info: *mut siginfo_t, ptr: *mut ::c_void),
541540
}
542541

543542
pub struct sigaction {
544-
#[cfg(libc_union)]
545543
pub sa_union: __sigaction_sa_union,
546544
pub sa_mask: sigset_t,
547545
pub sa_flags: ::c_int,
548546
}
549547

550-
#[cfg(libc_union)]
551548
pub union __poll_ctl_ext_u {
552549
pub addr: *mut ::c_void,
553550
pub data32: u32,
@@ -559,15 +556,13 @@ s_no_extra_traits! {
559556
pub command: u8,
560557
pub events: ::c_short,
561558
pub fd: ::c_int,
562-
#[cfg(libc_union)]
563559
pub u: __poll_ctl_ext_u,
564560
pub reversed64: [u64; 6],
565561
}
566562
}
567563

568564
cfg_if! {
569565
if #[cfg(feature = "extra_traits")] {
570-
#[cfg(libc_union)]
571566
impl PartialEq for __sigaction_sa_union {
572567
fn eq(&self, other: &__sigaction_sa_union) -> bool {
573568
unsafe {
@@ -576,9 +571,7 @@ cfg_if! {
576571
}
577572
}
578573
}
579-
#[cfg(libc_union)]
580574
impl Eq for __sigaction_sa_union {}
581-
#[cfg(libc_union)]
582575
impl ::fmt::Debug for __sigaction_sa_union {
583576
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
584577
f.debug_struct("__sigaction_sa_union")
@@ -587,7 +580,6 @@ cfg_if! {
587580
.finish()
588581
}
589582
}
590-
#[cfg(libc_union)]
591583
impl ::hash::Hash for __sigaction_sa_union {
592584
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
593585
unsafe {
@@ -599,36 +591,29 @@ cfg_if! {
599591

600592
impl PartialEq for sigaction {
601593
fn eq(&self, other: &sigaction) -> bool {
602-
#[cfg(libc_union)]
603-
let union_eq = self.sa_union == other.sa_union;
604-
#[cfg(not(libc_union))]
605-
let union_eq = true;
606594
self.sa_mask == other.sa_mask
607595
&& self.sa_flags == other.sa_flags
608-
&& union_eq
596+
&& self.sa_union == other.sa_union
609597
}
610598
}
611599
impl Eq for sigaction {}
612600
impl ::fmt::Debug for sigaction {
613601
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
614-
let mut struct_formatter = f.debug_struct("sigaction");
615-
#[cfg(libc_union)]
616-
struct_formatter.field("sa_union", &self.sa_union);
617-
struct_formatter.field("sa_mask", &self.sa_mask);
618-
struct_formatter.field("sa_flags", &self.sa_flags);
619-
struct_formatter.finish()
602+
f.debug_struct("sigaction")
603+
.field("sa_union", &self.sa_union)
604+
.field("sa_mask", &self.sa_mask)
605+
.field("sa_flags", &self.sa_flags)
606+
.finish()
620607
}
621608
}
622609
impl ::hash::Hash for sigaction {
623610
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
624-
#[cfg(libc_union)]
625611
self.sa_union.hash(state);
626612
self.sa_mask.hash(state);
627613
self.sa_flags.hash(state);
628614
}
629615
}
630616

631-
#[cfg(libc_union)]
632617
impl PartialEq for __poll_ctl_ext_u {
633618
fn eq(&self, other: &__poll_ctl_ext_u) -> bool {
634619
unsafe {
@@ -638,9 +623,7 @@ cfg_if! {
638623
}
639624
}
640625
}
641-
#[cfg(libc_union)]
642626
impl Eq for __poll_ctl_ext_u {}
643-
#[cfg(libc_union)]
644627
impl ::fmt::Debug for __poll_ctl_ext_u {
645628
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
646629
f.debug_struct("__poll_ctl_ext_u")
@@ -650,7 +633,6 @@ cfg_if! {
650633
.finish()
651634
}
652635
}
653-
#[cfg(libc_union)]
654636
impl ::hash::Hash for __poll_ctl_ext_u {
655637
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
656638
unsafe {
@@ -663,30 +645,25 @@ cfg_if! {
663645

664646
impl PartialEq for poll_ctl_ext {
665647
fn eq(&self, other: &poll_ctl_ext) -> bool {
666-
#[cfg(libc_union)]
667-
let union_eq = self.u == other.u;
668-
#[cfg(not(libc_union))]
669-
let union_eq = true;
670648
self.version == other.version
671649
&& self.command == other.command
672650
&& self.events == other.events
673651
&& self.fd == other.fd
674652
&& self.reversed64 == other.reversed64
675-
&& union_eq
653+
&& self.u == other.u
676654
}
677655
}
678656
impl Eq for poll_ctl_ext {}
679657
impl ::fmt::Debug for poll_ctl_ext {
680658
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
681-
let mut struct_formatter = f.debug_struct("poll_ctl_ext");
682-
struct_formatter.field("version", &self.version);
683-
struct_formatter.field("command", &self.command);
684-
struct_formatter.field("events", &self.events);
685-
struct_formatter.field("fd", &self.fd);
686-
#[cfg(libc_union)]
687-
struct_formatter.field("u", &self.u);
688-
struct_formatter.field("reversed64", &self.reversed64);
689-
struct_formatter.finish()
659+
f.debug_struct("poll_ctl_ext")
660+
.field("version", &self.version)
661+
.field("command", &self.command)
662+
.field("events", &self.events)
663+
.field("fd", &self.fd)
664+
.field("u", &self.u)
665+
.field("reversed64", &self.reversed64)
666+
.finish()
690667
}
691668
}
692669
impl ::hash::Hash for poll_ctl_ext {
@@ -695,7 +672,6 @@ cfg_if! {
695672
self.command.hash(state);
696673
self.events.hash(state);
697674
self.fd.hash(state);
698-
#[cfg(libc_union)]
699675
self.u.hash(state);
700676
self.reversed64.hash(state);
701677
}

0 commit comments

Comments
 (0)