Skip to content

libc: make structs non_exhaustive by default. #4579

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mbyx
Copy link
Contributor

@mbyx mbyx commented Jul 25, 2025

Description

By default all structs that use the s and s_no_extra_traits macros are now non_exhaustive. Structs can opt out of this if their first attribute is #[@not_non_exhaustive].

The @ was necessary so that Rust could differentiate between a normal attribute (which cannot have an @) and this. Another possible syntax that we could use instead is #[@not(non_exhaustive)].

Sources

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

/// Use [`s_no_extra_traits`] for structs where the `extra_traits` feature does not
/// make sense, and for unions.
macro_rules! s {
($(
$(#[@$not_non_exhaustive:ident])*
Copy link
Contributor

Choose a reason for hiding this comment

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

This should just be able to match a literal, right?

Suggested change
$(#[@$not_non_exhaustive:ident])*
$(#[not_non_exhaustive])?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, it fails with "attempted to repeat an expression containing no syntax variables"

@mbyx mbyx force-pushed the libc-non-exhaustive branch from d10b5ad to 12de1ba Compare July 26, 2025 15:17
@mbyx
Copy link
Contributor Author

mbyx commented Jul 26, 2025

The errors are strange, is it because ctest does not support some syntax? It seems to fail for c_enum as well but that hasn't been touched.

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

Successfully merging this pull request may close these issues.

3 participants