internal: add tuple struct support in pin_data and pin_init!#113
Open
mqqz wants to merge 3 commits intoRust-for-Linux:mainfrom
Open
internal: add tuple struct support in pin_data and pin_init!#113mqqz wants to merge 3 commits intoRust-for-Linux:mainfrom
pin_data and pin_init!#113mqqz wants to merge 3 commits intoRust-for-Linux:mainfrom
Conversation
b3f93db to
cd3f0a3
Compare
Introduce `FieldInfo` struct to encapsulate field and other relevant data (e.g. pinned and member name) to abstract over named/unnamed fields. Also, generate projections and pin-data accessors for unnamed members. Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
Refactor to parse initialiser keys as `Member` (named or tuple index).
Additionally, extend init parser to support both tuple-like init
constructor e.g. `Foo(a, <- b, c)` and brace syntax e.g.
`Foo{0 : a, 1 <- b, 2: c}`.
Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
Tests include:
- `tests/tuple_struct.rs`
- `tests/ui/compile-fail/tuple_{duplicate,invalid,missing}_field.rs`
- `tests/ui/compile-fail/tuple_shorthand.rs`
- `tests/ui/expand/pin_{data,init}`
Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extend
pin_dataandpin_init!to support tuple struct syntax.pin_data(internal/src/pin_data.rs):FieldInfostructpin_init!(internal/src/init.rs):syn::Member(named or tuple index)Foo(a, <- b, c)Foo{0 : a, 1 <- b, 2: c}Testing:
tests/tuple_struct.rstests/ui/compile-fail/tuple_{duplicate,invalid,missing}_field.rstests/ui/compile-fail/tuple_shorthand.rstests/ui/expand/pin_{data,init}Note that currently for tuple struct internal fields identifiers like
_0(for the first index) which clippy doesn't like. I'm not sure whether it's better to change naming or add#[allow(clippy::just_underscores_and_digits)](I don't want to go through the effort of spamming clippy and changing all expanded tests just yet).Closes: #85