diff --git a/pdl-compiler/src/backends/rust/parser.rs b/pdl-compiler/src/backends/rust/parser.rs index 050abbf..379d294 100644 --- a/pdl-compiler/src/backends/rust/parser.rs +++ b/pdl-compiler/src/backends/rust/parser.rs @@ -429,7 +429,7 @@ impl<'a> FieldParser<'a> { // The element width is not known, but the array // element count is known statically. Parse elements // item by item as an array. - let count = syn::Index::from(*count); + let count = proc_macro2::Literal::usize_unsuffixed(*count); self.tokens.extend(quote! { // TODO(mgeisler): use // https://doc.rust-lang.org/std/array/fn.try_from_fn.html @@ -466,12 +466,12 @@ impl<'a> FieldParser<'a> { (ElementWidth::Static(element_width), ArrayShape::Static(count)) => { // The element width is known, and the array element // count is known statically. - let count = syn::Index::from(*count); + let count = proc_macro2::Literal::usize_unsuffixed(*count); // This creates a nicely formatted size. let array_size = if element_width == 1 { quote!(#count) } else { - let element_width = syn::Index::from(element_width); + let element_width = proc_macro2::Literal::usize_unsuffixed(element_width); quote!(#count * #element_width) }; self.check_size(&span, "e! { #array_size }); @@ -511,7 +511,7 @@ impl<'a> FieldParser<'a> { }; let count_field = format_ident!("{id}_count"); let array_count = if element_width != 1 { - let element_width = syn::Index::from(element_width); + let element_width = proc_macro2::Literal::usize_unsuffixed(element_width); self.tokens.extend(quote! { if #array_size % #element_width != 0 { return Err(DecodeError::InvalidArraySize { @@ -738,7 +738,7 @@ impl<'a> FieldParser<'a> { 0, "Payload field offset from end of packet is not a multiple of 8" ); - let offset_from_end = syn::Index::from(offset_from_end / 8); + let offset_from_end = proc_macro2::Literal::usize_unsuffixed(offset_from_end / 8); self.check_size(self.span, "e!(#offset_from_end)); self.tokens.extend(quote! { let payload = #span[..#span.len() - #offset_from_end].to_vec(); diff --git a/pdl-compiler/src/backends/rust/serializer.rs b/pdl-compiler/src/backends/rust/serializer.rs index 0af464c..22d5abe 100644 --- a/pdl-compiler/src/backends/rust/serializer.rs +++ b/pdl-compiler/src/backends/rust/serializer.rs @@ -59,7 +59,7 @@ impl std::ops::AddAssign<&RuntimeSize> for RuntimeSize { impl quote::ToTokens for RuntimeSize { fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { - let constant = syn::Index::from(self.constant); + let constant = proc_macro2::Literal::usize_unsuffixed(self.constant); tokens.extend(match self { RuntimeSize { variable, .. } if variable.is_empty() => quote! { #constant }, RuntimeSize { variable, constant: 0 } => quote! { #(#variable)+* }, @@ -336,11 +336,12 @@ impl Encoder { } (ast::FieldDesc::Array { width: Some(width), .. }, _) | (ast::FieldDesc::Array { .. }, Some(ast::DeclDesc::Enum { width, .. })) => { - let byte_width = syn::Index::from(width / 8); - if byte_width.index == 1 { + let size = width / 8; + if size == 1 { quote! { self.#field_name.len() } } else { - quote! { (self.#field_name.len() * #byte_width) } + let size = proc_macro2::Literal::usize_unsuffixed(size); + quote! { (self.#field_name.len() * #size) } } } (ast::FieldDesc::Array { .. }, _) => { @@ -467,7 +468,7 @@ impl Encoder { self.tokens.extend(match values.as_slice() { [] => { let buf = format_ident!("{}", self.buf); - let count = syn::Index::from(self.bit_shift / 8); + let count = proc_macro2::Literal::usize_unsuffixed(self.bit_shift / 8); quote! { #buf.put_bytes(0, #count); }