Consider the following test:
#[test]
fn test_const_generics() -> Result<()> {
let tokens = quote! {
<foo<1>/>
};
let nodes = parse2(tokens)?;
let element = get_element(&nodes, 0);
assert_eq!(element.name().to_string(), "foo");
let param: TypeParam = parse_quote!(1);
assert_eq!(element.open_tag.generics.type_params().next(), Some(¶m));
Ok(())
}
This follows the same form as the existing test_generics(), but uses a const generic.
This fails to parse, because rstml currently tries to parse these generics into [syn::Generics]
(https://docs.rs/syn/latest/syn/struct.Generics.html):
|
pub struct OpenTag { |
|
pub token_lt: Token![<], |
|
pub name: NodeName, |
|
pub generics: syn::Generics, |
But syn::Generics is the syntax for generics "lifetimes and type parameters attached to a declaration of a function, enum, trait, etc." i.e., for a const generic its GenericParam is a ConstParam as in a declaration, not an invocation: i.e., it's const LENGTH: usize, not 3.
I made some progress (66e8e6f) in moving this over to parse the generics as generic arguments rather than declarations, but other tests are written to rely on access to some methods from syn::Generics. So I thought I'd stop here and ask your thoughts!
(Or, if const generics are intended to be supported in another way, let me know!)
--> rstml/tests/test.rs:755:42
|
755 | assert_eq!(element.open_tag.generics.lifetimes().next(), Some(¶m));
| ^^^^^^^^^ method not found in `TagGenerics`
error[E0599]: no method named `type_params` found for struct `TagGenerics` in the current scope
--> rstml/tests/test.rs:777:14
|
772 | / element
773 | | .close_tag
774 | | .as_ref()
775 | | .unwrap()
776 | | .generics
777 | | .type_params()
| | -^^^^^^^^^^^ method not found in `TagGenerics`
| |_____________|
|
error[E0599]: no method named `lifetimes` found for struct `TagGenerics` in the current scope
--> rstml/tests/test.rs:787:14
|
782 | / element
783 | | .close_tag
784 | | .as_ref()
785 | | .unwrap()
786 | | .generics
787 | | .lifetimes()
| | -^^^^^^^^^ method not found in `TagGenerics`
| |_____________|
Consider the following test:
This follows the same form as the existing
test_generics(), but uses a const generic.This fails to parse, because
rstmlcurrently tries to parse these generics into [syn::Generics](https://docs.rs/syn/latest/syn/struct.Generics.html):
rstml/rstml/src/node/atoms.rs
Lines 134 to 137 in 51f2ff9
But
syn::Genericsis the syntax for generics "lifetimes and type parameters attached to a declaration of a function, enum, trait, etc." i.e., for a const generic itsGenericParamis aConstParamas in a declaration, not an invocation: i.e., it'sconst LENGTH: usize, not3.I made some progress (66e8e6f) in moving this over to parse the generics as generic arguments rather than declarations, but other tests are written to rely on access to some methods from
syn::Generics. So I thought I'd stop here and ask your thoughts!(Or, if const generics are intended to be supported in another way, let me know!)