feat: allow slice! macro to index tuples (#2598)

* Allow slice! macro to index tuples

* Undo changes to component tests

---------

Co-authored-by: Greg Johnston <greg.johnston@gmail.com>
This commit is contained in:
SleeplessOne1917 2024-05-29 13:07:41 +00:00 committed by GitHub
parent 2f4fd87c05
commit 21a6551ce6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 6 deletions

View file

@ -11,7 +11,7 @@ use syn::{
struct SliceMacroInput {
root: syn::Ident,
path: Punctuated<syn::Ident, Token![.]>,
path: Punctuated<syn::Member, Token![.]>,
}
impl Parse for SliceMacroInput {
@ -19,7 +19,7 @@ impl Parse for SliceMacroInput {
let root: syn::Ident = input.parse()?;
input.parse::<Token![.]>()?;
// do not accept trailing punctuation
let path: Punctuated<syn::Ident, Token![.]> =
let path: Punctuated<syn::Member, Token![.]> =
Punctuated::parse_separated_nonempty(input)?;
if path.is_empty() {

View file

@ -10,9 +10,12 @@ pub struct OuterState {
#[derive(Clone, PartialEq, Default)]
pub struct InnerState {
inner_count: i32,
inner_name: String,
inner_tuple: InnerTuple,
}
#[derive(Clone, PartialEq, Default)]
pub struct InnerTuple(String);
#[test]
fn green() {
let _ = create_runtime();
@ -22,7 +25,7 @@ fn green() {
let (_, _) = slice!(outer_signal.count);
let (_, _) = slice!(outer_signal.inner.inner_count);
let (_, _) = slice!(outer_signal.inner.inner_name);
let (_, _) = slice!(outer_signal.inner.inner_tuple.0);
}
#[test]

View file

@ -14,7 +14,7 @@ error: expected `.`
|
= note: this error originates in the macro `slice` (in Nightly builds, run with -Z macro-backtrace for more info)
error: unexpected end of input, expected identifier
error: unexpected end of input, expected identifier or integer
--> tests/slice/red.rs:25:18
|
25 | let (_, _) = slice!(outer_signal.);
@ -22,7 +22,7 @@ error: unexpected end of input, expected identifier
|
= note: this error originates in the macro `slice` (in Nightly builds, run with -Z macro-backtrace for more info)
error: unexpected end of input, expected identifier
error: unexpected end of input, expected identifier or integer
--> tests/slice/red.rs:27:18
|
27 | let (_, _) = slice!(outer_signal.inner.);