macros: add support for exhaustive attribute - #5390
Conversation
exhaustive attrexhaustive attribute
8c61548 to
5a738cb
Compare
5a738cb to
f11b352
Compare
|
Could you base this on top of #5372? It looks like there may be some overlap. Feel free to leave a review there as well, if you have any suggestions. |
| @attr | ||
| attrs: { #[exhaustive] $($attrs:tt)* } | ||
| processed_attrs: { $($prev_attrs:tt)* } | ||
| found: { $_:tt } |
There was a problem hiding this comment.
found_exhaustive_attr or so, to make it more clear in other blocks without the comment
| macro_rules! fin { | ||
| (true decl: $(#[$attr:meta])* $vis:vis $name:ident { $($field:tt)* }) => { | ||
| $(#[$attr])* | ||
| $vis struct $name { $($field)* } | ||
| }; | ||
| (true default: { $($field_default:tt)* }) => { | ||
| Self { $($field_default)* } | ||
| }; | ||
|
|
||
| (false decl: $(#[$attr:meta])* $vis:vis $name:ident { $($field:tt)* }) => { | ||
| $(#[$attr])* | ||
| $vis struct $name { $($field)* __non_exhaustive: () } | ||
| }; | ||
| (false default: { $($field_default:tt)* }) => { | ||
| Self { $($field_default)* __non_exhaustive: () } | ||
| }; | ||
| } |
There was a problem hiding this comment.
Give this a more descriptive name, and prefer the field: $value pattern for matchers like the other macros have. That's easier to follow than needing to figure out what different token sequences indicate.
| // FIXME(rust-lang/rust#132699): get rid of this once we stop using the private | ||
| // field. | ||
| #![allow(clippy::manual_non_exhaustive)] |
There was a problem hiding this comment.
Can this be scoped to only where needed?
f11b352 to
f38fc87
Compare
This comment has been minimized.
This comment has been minimized.
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
Add support for `exhaustive` custom attribute to opt out of having the record have a `__non_exhaustive` field added to it. Modify `struct_with_default` to automatically add a private field to all records such that they are always built field-by-field in downstream crates.
72651eb to
f596ba7
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
☔ The latest upstream changes (possibly #5372) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Description
Attempts to take the first steps in closing #4080. This should
allow us to add a private field for each of the records declared within
s_with_defaultors_no_extra_traits_with_default.This should in turn enforce those records to be initialized field-by-field in
downstream crates, while avoiding the lint that currently pops up when using a
structmarkednon_exhaustivein FFI contexts.Checklist
libc-test/semverhave been updated*LASTor*MAXhave the standarddoc comment
cargo test -p libc-test --target mytarget); especiallyrelevant for platforms that may not be checked in CI
@rustbot label +stable-nominated