Skip to content

macros: forward cfg attributes to generated impls - #5372

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

macros: forward cfg attributes to generated impls#5372
telcharr wants to merge 2 commits into
rust-lang:mainfrom
telcharr:feature/default-macro-cfg

Conversation

@telcharr

@telcharr telcharr commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Description

Follow-up to #5257 for the cfg issue that was spotted, plus the same on Debug for unions.

Attributes are now split into cfg_attrs and other_attrs, both go on the type, only the cfgs repeat on the impl. Needed them as tt rather than meta so cfg is still matchable.

The generated impls also warn when the type or its fields are deprecated. s_no_extra_traits! got an allow(deprecated) for that but the newer macros never picked it up.

The splitting arms are duplicated between union_with_debug! and struct_with_default!. Sharing them needs a callback macro which felt worse to read, but let me know if you'd rather have that.

Checklist

  • Relevant tests in libc-test/semver have been updated
  • Commit messages permalink to headers for added or changed API
  • Placeholder or unstable values like *LAST or *MAX have the standard
    doc comment
  • Tested locally (cargo test -p libc-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 Aug 5, 2026

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry this took so long, one change then looks great

View changes since this review

Comment thread src/macros.rs
// The opposite of the configured-out types in `macro_checks`. With the `cfg` true the
// type and its `Default` both exist, and the other attributes still apply.
s_with_default! {
#[cfg(not(any()))]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can this and other tests use cfg(false), or does the MSRV check yell at that? If so, it's nicer to read than any()/not(any)

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

Labels

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