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

derive Debug on structures? #302

Closed
dimbleby opened this issue May 30, 2016 · 7 comments
Closed

derive Debug on structures? #302

dimbleby opened this issue May 30, 2016 · 7 comments

Comments

@dimbleby
Copy link
Contributor

It's my understanding that implementing Debug on structures is generally a Good Thing. Types provided by this library do not implement Debug. Is this by policy, or by omission?

(I tried some quick messing around with the s! macro and failed to persuade it to #[derive(Debug)]. But I suppose that this ought to be possible, if it is indeed desirable).

@kamalmarhubi
Copy link
Contributor

In #159 (comment), @alexcrichton said

Currently, however, the libc crate is intended to be as thin a wrapper as possible around the system libc, for example it only provides the guarantee that structs are Copy (which also forces a Clone impl).

At this time we're not looking for higher level abstractions in libc (e.g. any other form of "Rust code" like Eq or Hash). That's in general left to higher level libraries.

I expect this will apply to Debug as well. The aim, as I understand it, is that libc should be as close to nothing-but-declarations as possible.

@dimbleby
Copy link
Contributor Author

Interesting.

A couple of data points:

@alexcrichton
Copy link
Member

Oh this was actually something I forgot to implement. The intention of the original RFC was:

As a technical detail, all struct types exposed in libc will be guaranteed to implement the Copy and Clone traits. There will be an optional feature of the library to implement Debug for all structs, but it will be turned off by default.

That optional feature just hasn't been implemented yet. Shouldn't be too hard to do though!

@kamalmarhubi
Copy link
Contributor

Giving this a shot. Two issues so far:

  • can't derive Debug on structs that have large arrays embedded, since it's only implemented up to 32-element arrays, so there will be some messiness instead of hiding it all away in the s! macro
  • I think there's a bug with derive(Debug) when fields have a #[cfg(...)] attribute on them. The expanded impl is referencing the fields that are excluded by the attribute, leading to either matching a non-existent field, or binding the same field twice. I can't repro in a top-level struct outside of libc, still taking a look.

Susurrus pushed a commit to Susurrus/libc that referenced this issue Mar 26, 2017
tests: Disable test_sigwait on apple platforms

After rust-lang#292 was merged, this flakiness remained. I observe it only on
Darwin, hence the targetted disabling until there's been more
investigation.
@Susurrus
Copy link
Contributor

Susurrus commented Dec 6, 2017

I just ran into this again today with both Eq and Debug. For developing nix we have a large number of structs that are just newtype wrappers around libc types and we'd like to derive some of these traits on these structs. Many of these structs vary per-platform, and we support a lot of platforms, so it's tough to manually implement some of these.

So in the 1.5 years since this issue was opened a lot has changed. With compile times actively seeing work over every release cycle and also the Rust API Guidelines specifying that many derives should be added for structs, I'd like to revisit this. I'll write up an RFC this week and we'll see where we get!

@Susurrus
Copy link
Contributor

Susurrus commented Dec 6, 2017

I've now filed a PR for this RFC: rust-lang/rfcs#2235

@gnzlbg
Copy link
Contributor

gnzlbg commented Feb 21, 2019

The RFC was partially implemented, closing this in favor of the tracking issue: rust-lang/rust#57715

@gnzlbg gnzlbg closed this as completed Feb 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants