Skip to content

Make extra_traits work with rustc-dep-of-std #2074

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

Closed
wants to merge 6 commits into from
Closed
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
6 changes: 3 additions & 3 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ macro_rules! s {
(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
__item! {
#[repr(C)]
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
#[cfg_attr(feature = "extra_traits", derive(core::fmt::Debug, core::cmp::Eq, core::hash::Hash, core::cmp::PartialEq))]
Copy link
Member

Choose a reason for hiding this comment

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

According to CI this doesn't work on Rust 1.13.

Copy link
Author

Choose a reason for hiding this comment

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

Hm, that's weird. I don't know what the problem is with this syntax. I guess I'll have to install rustc 1.13 and experiment with it.

Copy link
Author

Choose a reason for hiding this comment

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

These are the errors:

error: expected `,`, found `::`
  --> src/macros.rs:76:61
   |
76 |             #[cfg_attr(feature = "extra_traits", derive(core::fmt::Debug, core::cmp::Eq, core::hash::Hash, core::cmp::PartialEq))]
   |                                                             ^^

error: expected `,`, found `::`
  --> src/macros.rs:76:61
   |
76 |             #[cfg_attr(feature = "extra_traits", derive(core::fmt::Debug, core::cmp::Eq, core::hash::Hash, core::cmp::PartialEq))]
   |                                                             ^^

error: expected `]`, found `::`
  --> src/macros.rs:76:61
   |
76 |             #[cfg_attr(feature = "extra_traits", derive(core::fmt::Debug, core::cmp::Eq, core::hash::Hash, core::cmp::PartialEq))]
   |                                                             ^^

error: Could not compile `libc`.

I have no idea what the problem is and how to work around this. Anyone have any ideas?

Copy link
Author

Choose a reason for hiding this comment

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

I guess qualified paths were not allowed in derive arguments in 1.13.

When building libc for rustc we know we're using a more recent version, so ideally I wouldn't have to deal with this.

Copy link
Member

Choose a reason for hiding this comment

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

We can use cfg(feature = "rustc-dep-of-std") for it.

Copy link
Author

Choose a reason for hiding this comment

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

I don't understand how that would work. The core::fmt::... syntax will still be there and rustc 1.13 will try to parse it, no?

Copy link
Member

Choose a reason for hiding this comment

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

That syntax won't work on 1.13: https://rust.godbolt.org/z/f9nf9rTTG

So, we want to make it work under rustc-dep-of-std, right? Then we can hide them behind rustc-dep-of-std, it's fine because we suppose it's used on rust-lang/rust.

#[allow(deprecated)]
$(#[$attr])*
pub struct $i { $($field)* }
Expand Down Expand Up @@ -127,7 +127,7 @@ macro_rules! s_no_extra_traits {
macro_rules! e {
($($(#[$attr:meta])* pub enum $i:ident { $($field:tt)* })*) => ($(
__item! {
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
#[cfg_attr(feature = "extra_traits", derive(core::fmt::Debug, core::cmp::Eq, core::hash::Hash, core::cmp::PartialEq))]
$(#[$attr])*
pub enum $i { $($field)* }
}
Expand All @@ -142,7 +142,7 @@ macro_rules! e {
macro_rules! s_paren {
($($(#[$attr:meta])* pub struct $i:ident ( $($field:tt)* ); )* ) => ($(
__item! {
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
#[cfg_attr(feature = "extra_traits", derive(core::fmt::Debug, core::cmp::Eq, core::hash::Hash, core::cmp::PartialEq))]
$(#[$attr])*
pub struct $i ( $($field)* );
}
Expand Down
11 changes: 9 additions & 2 deletions src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
//! x86_64-specific definitions for 64-bit linux-like values

cfg_if! {
if #[cfg(feature = "extra_traits")] {
use core::cmp::{Eq, PartialEq};
use core::iter::Iterator;
}
}

pub type c_char = i8;
pub type wchar_t = i32;
pub type nlink_t = u64;
Expand Down Expand Up @@ -332,7 +339,7 @@ cfg_if! {
impl Eq for user_fpregs_struct {}

impl ::fmt::Debug for user_fpregs_struct {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
fn fmt<'a>(&self, f: &mut ::fmt::Formatter<'a>) -> ::fmt::Result {
f.debug_struct("user_fpregs_struct")
.field("cwd", &self.cwd)
.field("ftw", &self.ftw)
Expand Down Expand Up @@ -377,7 +384,7 @@ cfg_if! {
impl Eq for ucontext_t {}

impl ::fmt::Debug for ucontext_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
fn fmt<'a>(&self, f: &mut ::fmt::Formatter<'a>) -> ::fmt::Result {
f.debug_struct("ucontext_t")
.field("uc_flags", &self.uc_flags)
.field("uc_link", &self.uc_link)
Expand Down
9 changes: 8 additions & 1 deletion src/unix/linux_like/linux/gnu/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
cfg_if! {
if #[cfg(feature = "extra_traits")] {
use core::cmp::{Eq, PartialEq};
use core::iter::Iterator;
}
}

pub type pthread_t = c_ulong;
pub type __priority_which_t = ::c_uint;
pub type __rlimit_resource_t = ::c_uint;
Expand Down Expand Up @@ -453,7 +460,7 @@ cfg_if! {
impl Eq for utmpx {}

impl ::fmt::Debug for utmpx {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
fn fmt<'a>(&self, f: &mut ::fmt::Formatter<'a>) -> ::fmt::Result {
f.debug_struct("utmpx")
.field("ut_type", &self.ut_type)
.field("ut_pid", &self.ut_pid)
Expand Down
26 changes: 17 additions & 9 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
//! Linux-specific definitions for linux-like values

cfg_if! {
if #[cfg(feature = "extra_traits")] {
use core::cmp::{Eq, PartialEq};
use core::fmt::Debug;
use core::iter::Iterator;
}
}

pub type useconds_t = u32;
pub type dev_t = u64;
pub type socklen_t = u32;
Expand Down Expand Up @@ -627,7 +635,7 @@ cfg_if! {
}
impl Eq for sockaddr_nl {}
impl ::fmt::Debug for sockaddr_nl {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
fn fmt<'a>(&self, f: &mut ::fmt::Formatter<'a>) -> ::fmt::Result {
f.debug_struct("sockaddr_nl")
.field("nl_family", &self.nl_family)
.field("nl_pid", &self.nl_pid)
Expand Down Expand Up @@ -660,7 +668,7 @@ cfg_if! {
impl Eq for dirent {}

impl ::fmt::Debug for dirent {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
fn fmt<'a>(&self, f: &mut ::fmt::Formatter<'a>) -> ::fmt::Result {
f.debug_struct("dirent")
.field("d_ino", &self.d_ino)
.field("d_off", &self.d_off)
Expand Down Expand Up @@ -698,7 +706,7 @@ cfg_if! {
impl Eq for dirent64 {}

impl ::fmt::Debug for dirent64 {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
fn fmt<'a>(&self, f: &mut ::fmt::Formatter<'a>) -> ::fmt::Result {
f.debug_struct("dirent64")
.field("d_ino", &self.d_ino)
.field("d_off", &self.d_off)
Expand Down Expand Up @@ -728,7 +736,7 @@ cfg_if! {
impl Eq for pthread_cond_t {}

impl ::fmt::Debug for pthread_cond_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
fn fmt<'a>(&self, f: &mut ::fmt::Formatter<'a>) -> ::fmt::Result {
f.debug_struct("pthread_cond_t")
// FIXME: .field("size", &self.size)
.finish()
Expand All @@ -750,7 +758,7 @@ cfg_if! {
impl Eq for pthread_mutex_t {}

impl ::fmt::Debug for pthread_mutex_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
fn fmt<'a>(&self, f: &mut ::fmt::Formatter<'a>) -> ::fmt::Result {
f.debug_struct("pthread_mutex_t")
// FIXME: .field("size", &self.size)
.finish()
Expand All @@ -772,7 +780,7 @@ cfg_if! {
impl Eq for pthread_rwlock_t {}

impl ::fmt::Debug for pthread_rwlock_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
fn fmt<'a>(&self, f: &mut ::fmt::Formatter<'a>) -> ::fmt::Result {
f.debug_struct("pthread_rwlock_t")
// FIXME: .field("size", &self.size)
.finish()
Expand Down Expand Up @@ -806,7 +814,7 @@ cfg_if! {
impl Eq for sockaddr_alg {}

impl ::fmt::Debug for sockaddr_alg {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
fn fmt<'a>(&self, f: &mut ::fmt::Formatter<'a>) -> ::fmt::Result {
f.debug_struct("sockaddr_alg")
.field("salg_family", &self.salg_family)
.field("salg_type", &self.salg_type)
Expand Down Expand Up @@ -851,7 +859,7 @@ cfg_if! {

#[allow(deprecated)]
impl ::fmt::Debug for af_alg_iv {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
fn fmt<'a>(&self, f: &mut ::fmt::Formatter<'a>) -> ::fmt::Result {
f.debug_struct("af_alg_iv")
.field("ivlen", &self.ivlen)
.finish()
Expand All @@ -875,7 +883,7 @@ cfg_if! {
}
impl Eq for mq_attr {}
impl ::fmt::Debug for mq_attr {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
fn fmt<'a>(&self, f: &mut ::fmt::Formatter<'a>) -> ::fmt::Result {
f.debug_struct("mq_attr")
.field("mq_flags", &self.mq_flags)
.field("mq_maxmsg", &self.mq_maxmsg)
Expand Down
18 changes: 13 additions & 5 deletions src/unix/linux_like/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
cfg_if! {
if #[cfg(feature = "extra_traits")] {
use core::cmp::{Eq, PartialEq};
use core::fmt::Debug;
use core::iter::Iterator;
}
}

pub type sa_family_t = u16;
pub type speed_t = ::c_uint;
pub type tcflag_t = ::c_uint;
Expand Down Expand Up @@ -264,7 +272,7 @@ cfg_if! {
}
impl Eq for epoll_event {}
impl ::fmt::Debug for epoll_event {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
fn fmt<'a>(&self, f: &mut ::fmt::Formatter<'a>) -> ::fmt::Result {
let events = self.events;
let u64 = self.u64;
f.debug_struct("epoll_event")
Expand Down Expand Up @@ -294,7 +302,7 @@ cfg_if! {
}
impl Eq for sockaddr_un {}
impl ::fmt::Debug for sockaddr_un {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
fn fmt<'a>(&self, f: &mut ::fmt::Formatter<'a>) -> ::fmt::Result {
f.debug_struct("sockaddr_un")
.field("sun_family", &self.sun_family)
// FIXME: .field("sun_path", &self.sun_path)
Expand Down Expand Up @@ -322,7 +330,7 @@ cfg_if! {
impl Eq for sockaddr_storage {}

impl ::fmt::Debug for sockaddr_storage {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
fn fmt<'a>(&self, f: &mut ::fmt::Formatter<'a>) -> ::fmt::Result {
f.debug_struct("sockaddr_storage")
.field("ss_family", &self.ss_family)
.field("__ss_align", &self.__ss_align)
Expand Down Expand Up @@ -375,7 +383,7 @@ cfg_if! {
impl Eq for utsname {}

impl ::fmt::Debug for utsname {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
fn fmt<'a>(&self, f: &mut ::fmt::Formatter<'a>) -> ::fmt::Result {
f.debug_struct("utsname")
// FIXME: .field("sysname", &self.sysname)
// FIXME: .field("nodename", &self.nodename)
Expand Down Expand Up @@ -409,7 +417,7 @@ cfg_if! {
}
impl Eq for sigevent {}
impl ::fmt::Debug for sigevent {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
fn fmt<'a>(&self, f: &mut ::fmt::Formatter<'a>) -> ::fmt::Result {
f.debug_struct("sigevent")
.field("sigev_value", &self.sigev_value)
.field("sigev_signo", &self.sigev_signo)
Expand Down
3 changes: 3 additions & 0 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
//! More functions and definitions can be found in the more specific modules
//! according to the platform in question.

#[cfg(feature = "extra_traits")]
use core::fmt::Debug;

pub type c_schar = i8;
pub type c_uchar = u8;
pub type c_short = i16;
Expand Down