Skip to content

add macros for generating Default impls#5257

Open
telcharr wants to merge 6 commits into
rust-lang:mainfrom
telcharr:feature/default-macro
Open

add macros for generating Default impls#5257
telcharr wants to merge 6 commits into
rust-lang:mainfrom
telcharr:feature/default-macro

Conversation

@telcharr

@telcharr telcharr commented Jul 7, 2026

Copy link
Copy Markdown

Description

Adds impl_default!, s_with_default!, and s_no_extra_traits_with_default! as a start for #4975. Unions get no implicit Default so a union field would need to supply one via #[custom_default(unsafe { mem::zeroed::<U>() })]. As discussed, custom_default needs to be the first attribute on a field since the macro matches it literally.

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI

@rustbot label +stable-nominated

@rustbot rustbot added S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Jul 7, 2026

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for putting this together! It looks very workable. I have a handful of requests but all style/maintainability.

Would you be able to add a commit that makes use of this (replacing s!) in a few small places so we make sure it works in situ? Fine to do that in a separate PR, if you prefer, as long as it's coming soon.

View changes since this review

Comment thread src/macros.rs Outdated
Comment thread src/macros.rs Outdated
Comment thread src/macros.rs Outdated
Comment thread src/macros.rs Outdated
Comment thread src/macros.rs Outdated
Comment thread src/macros.rs
Comment thread src/macros.rs Outdated
Comment thread src/macros.rs Outdated
@rustbot

rustbot commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@telcharr

Copy link
Copy Markdown
Author

Added a commit converting new/linux_uapi/linux/can.rs since it hits most cases. The only things it doesn't cover is #[cfg] and doc comments. If you'd like me to add a new commit implementing the macros that covers those cases let me know.

@rustbot ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-linux S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants