From f6312f5e8c5d0c5ce25ca0839514fd56ab7f6267 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sun, 24 Sep 2023 20:12:13 +0200 Subject: [PATCH 1/4] feat(sol-macro): improve type expansion --- crates/sol-macro/src/expand/mod.rs | 56 ++++++------ crates/sol-macro/src/expand/ty.rs | 116 ++++++++++++++++++++---- crates/sol-types/src/lib.rs | 4 +- crates/sol-types/src/types/data_type.rs | 3 + crates/sol-types/tests/sol.rs | 13 ++- 5 files changed, 138 insertions(+), 54 deletions(-) diff --git a/crates/sol-macro/src/expand/mod.rs b/crates/sol-macro/src/expand/mod.rs index f2c3ed0823..f06452561e 100644 --- a/crates/sol-macro/src/expand/mod.rs +++ b/crates/sol-macro/src/expand/mod.rs @@ -2,14 +2,15 @@ use crate::{ attr::{self, SolAttrs}, + expand::ty::expand_rust_type, utils::{self, ExprArray}, }; use ast::{ File, Item, ItemError, ItemEvent, ItemFunction, Parameters, SolIdent, SolPath, Spanned, Type, VariableDeclaration, Visit, }; -use proc_macro2::{Ident, Span, TokenStream}; -use quote::{format_ident, quote}; +use proc_macro2::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree}; +use quote::{format_ident, quote, TokenStreamExt}; use std::{borrow::Borrow, collections::HashMap, fmt::Write}; use syn::{parse_quote, Attribute, Error, Result}; @@ -429,32 +430,21 @@ impl ExpCtxt<'_> { } // helper functions + /// Expands a list of parameters into a list of struct fields. -/// -/// See [`expand_field`]. fn expand_fields

(params: &Parameters

) -> impl Iterator + '_ { - params - .iter() - .enumerate() - .map(|(i, var)| expand_field(i, &var.ty, var.name.as_ref(), var.attrs.as_ref())) -} - -/// Expands a single parameter into a struct field. -fn expand_field( - i: usize, - ty: &Type, - name: Option<&SolIdent>, - attrs: &Vec, -) -> TokenStream { - let name = anon_name((i, name)); - let ty = expand_type(ty); - quote! { - #(#attrs)* - pub #name: <#ty as ::alloy_sol_types::SolType>::RustType - } + params.iter().enumerate().map(|(i, var)| { + let name = anon_name((i, var.name.as_ref())); + let ty = expand_rust_type(&var.ty); + let attrs = &var.attrs; + quote! { + #(#attrs)* + pub #name: #ty + } + }) } -/// Generates an anonymous name from an integer. Used in `anon_name` +/// Generates an anonymous name from an integer. Used in [`anon_name`]. #[inline] pub fn generate_name(i: usize) -> Ident { format_ident!("_{i}") @@ -522,12 +512,18 @@ fn expand_from_into_tuples

(name: &Ident, fields: &Parameters

) -> TokenStre fn expand_tuple_types<'a, I: IntoIterator>( types: I, ) -> (TokenStream, TokenStream) { - let mut sol_tuple = TokenStream::new(); - let mut rust_tuple = TokenStream::new(); + let mut sol = TokenStream::new(); + let mut rust = TokenStream::new(); + let comma = Punct::new(',', Spacing::Alone); for ty in types { - let expanded = expand_type(ty); - sol_tuple.extend(quote!(#expanded,)); - rust_tuple.extend(quote!(<#expanded as ::alloy_sol_types::SolType>::RustType,)); + ty::rec_expand_type(ty, &mut sol); + sol.append(comma.clone()); + + ty::rec_expand_rust_type(ty, &mut rust); + rust.append(comma.clone()); } - (quote!((#sol_tuple)), quote!((#rust_tuple))) + ( + TokenStream::from(TokenTree::Group(Group::new(Delimiter::Parenthesis, sol))), + TokenStream::from(TokenTree::Group(Group::new(Delimiter::Parenthesis, rust))), + ) } diff --git a/crates/sol-macro/src/expand/ty.rs b/crates/sol-macro/src/expand/ty.rs index ab4ecdb10c..5fe1719381 100644 --- a/crates/sol-macro/src/expand/ty.rs +++ b/crates/sol-macro/src/expand/ty.rs @@ -3,17 +3,29 @@ use super::ExpCtxt; use crate::expand::generate_name; use ast::{EventParameter, Item, Parameters, Spanned, Type, TypeArray, VariableDeclaration}; -use proc_macro2::{Literal, TokenStream}; +use proc_macro2::{Ident, Literal, TokenStream}; use quote::{quote, quote_spanned, ToTokens}; use std::{fmt, num::NonZeroU16}; -/// Expands a single [`Type`] recursively. +/// Expands a single [`Type`] recursively to its `alloy_sol_types::sol_data` +/// equivalent. pub fn expand_type(ty: &Type) -> TokenStream { let mut tokens = TokenStream::new(); rec_expand_type(ty, &mut tokens); tokens } +/// Expands a single [`Type`] recursively to its Rust type equivalent. +/// +/// This is the same as `<#expand_type(ty) as SolType>::RustType`, but generates +/// nicer code for documentation and IDE/LSP support when the type is not +/// ambiguous. +pub fn expand_rust_type(ty: &Type) -> TokenStream { + let mut tokens = TokenStream::new(); + rec_expand_rust_type(ty, &mut tokens); + tokens +} + /// Expands a [`VariableDeclaration`] into an invocation of its types tokenize /// method. fn expand_tokenize_statement(var: &VariableDeclaration, i: usize) -> TokenStream { @@ -59,7 +71,7 @@ pub fn expand_event_tokenize_func<'a>( } /// The [`expand_type`] recursive implementation. -fn rec_expand_type(ty: &Type, tokens: &mut TokenStream) { +pub fn rec_expand_type(ty: &Type, tokens: &mut TokenStream) { let tts = match *ty { Type::Address(span, _) => quote_spanned! {span=> ::alloy_sol_types::sol_data::Address }, Type::Bool(span) => quote_spanned! {span=> ::alloy_sol_types::sol_data::Bool }, @@ -67,11 +79,9 @@ fn rec_expand_type(ty: &Type, tokens: &mut TokenStream) { Type::Bytes(span) => quote_spanned! {span=> ::alloy_sol_types::sol_data::Bytes }, Type::FixedBytes(span, size) => { - debug_assert!(size.get() <= 32); + assert!(size.get() <= 32); let size = Literal::u16_unsuffixed(size.get()); - quote_spanned! {span=> - ::alloy_sol_types::sol_data::FixedBytes<#size> - } + quote_spanned! {span=> ::alloy_sol_types::sol_data::FixedBytes<#size> } } Type::Int(span, size) | Type::Uint(span, size) => { let name = match ty { @@ -79,15 +89,13 @@ fn rec_expand_type(ty: &Type, tokens: &mut TokenStream) { Type::Uint(..) => "Uint", _ => unreachable!(), }; - let name = syn::Ident::new(name, span); + let name = Ident::new(name, span); let size = size.map_or(256, NonZeroU16::get); - debug_assert!(size <= 256 && size % 8 == 0); + assert!(size <= 256 && size % 8 == 0); let size = Literal::u16_unsuffixed(size); - quote_spanned! {span=> - ::alloy_sol_types::sol_data::#name<#size> - } + quote_spanned! {span=> ::alloy_sol_types::sol_data::#name<#size> } } Type::Tuple(ref tuple) => { @@ -103,13 +111,9 @@ fn rec_expand_type(ty: &Type, tokens: &mut TokenStream) { let ty = expand_type(&array.ty); let span = array.span(); if let Some(size) = array.size() { - quote_spanned! {span=> - ::alloy_sol_types::sol_data::FixedArray<#ty, #size> - } + quote_spanned! {span=> ::alloy_sol_types::sol_data::FixedArray<#ty, #size> } } else { - quote_spanned! {span=> - ::alloy_sol_types::sol_data::Array<#ty> - } + quote_spanned! {span=> ::alloy_sol_types::sol_data::Array<#ty> } } } Type::Function(ref function) => quote_spanned! {function.span()=> @@ -124,6 +128,82 @@ fn rec_expand_type(ty: &Type, tokens: &mut TokenStream) { tokens.extend(tts); } +// IMPORTANT: Keep in sync with `sol-types/src/types/data_type.rs` +/// The [`expand_rust_type`] recursive implementation. +pub fn rec_expand_rust_type(ty: &Type, tokens: &mut TokenStream) { + // Display sizes that match with the Rust type, otherwise we lose information + // (e.g. `uint24` displays the same as `uint32` because both use `u32`) + fn allowed_int_size(size: Option) -> bool { + matches!( + size.map_or(256, NonZeroU16::get), + 8 | 16 | 32 | 64 | 128 | 256 + ) + } + + let tts = match *ty { + Type::Address(span, _) => quote_spanned! {span=> ::alloy_sol_types::private::Address }, + Type::Bool(span) => return Ident::new("bool", span).to_tokens(tokens), + Type::String(span) => quote_spanned! {span=> ::alloy_sol_types::private::String }, + Type::Bytes(span) => quote_spanned! {span=> ::alloy_sol_types::private::Vec }, + + Type::FixedBytes(span, size) => { + assert!(size.get() <= 32); + let size = Literal::u16_unsuffixed(size.get()); + quote_spanned! {span=> ::alloy_sol_types::private::FixedBytes<#size> } + } + Type::Int(span, size) | Type::Uint(span, size) if allowed_int_size(size) => { + let size = size.map_or(256, NonZeroU16::get); + if size <= 128 { + let name = match ty { + Type::Int(..) => "i", + Type::Uint(..) => "u", + _ => unreachable!(), + }; + return Ident::new(&format!("{name}{size}"), span).to_tokens(tokens) + } + assert_eq!(size, 256); + match ty { + Type::Int(..) => quote_spanned! {span=> ::alloy_sol_types::private::I256 }, + Type::Uint(..) => quote_spanned! {span=> ::alloy_sol_types::private::U256 }, + _ => unreachable!(), + } + } + + Type::Tuple(ref tuple) => { + return tuple.paren_token.surround(tokens, |tokens| { + for pair in tuple.types.pairs() { + let (ty, comma) = pair.into_tuple(); + rec_expand_rust_type(ty, tokens); + comma.to_tokens(tokens); + } + }) + } + Type::Array(ref array) => { + let ty = expand_rust_type(&array.ty); + let span = array.span(); + if let Some(size) = array.size() { + quote_spanned! {span=> [#ty; #size] } + } else { + quote_spanned! {span=> ::alloy_sol_types::private::Vec<#ty> } + } + } + Type::Function(ref function) => quote_spanned! {function.span()=> + ::alloy_sol_types::private::Function + }, + Type::Mapping(ref mapping) => quote_spanned! {mapping.span()=> + ::core::compile_error!("Mapping types are not supported here") + }, + + // Exhaustive fallback to `SolType::RustType` + ref ty @ (Type::Int(..) | Type::Uint(..) | Type::Custom(_)) => { + let span = ty.span(); + let ty = expand_type(ty); + quote_spanned! {span=> <#ty as ::alloy_sol_types::SolType>::RustType } + } + }; + tokens.extend(tts); +} + /// Calculates the base ABI-encoded size of the given parameters in bytes. /// /// See [`type_base_data_size`] for more information. diff --git a/crates/sol-types/src/lib.rs b/crates/sol-types/src/lib.rs index 032d8c5d72..507d95fca4 100644 --- a/crates/sol-types/src/lib.rs +++ b/crates/sol-types/src/lib.rs @@ -206,7 +206,9 @@ pub mod private { string::{String, ToString}, vec::Vec, }; - pub use alloy_primitives::{bytes, keccak256, Bytes, FixedBytes, B256, U256}; + pub use alloy_primitives::{ + bytes, keccak256, Address, Bytes, FixedBytes, Function, Signed, Uint, B256, I256, U256, + }; pub use core::{convert::From, default::Default, option::Option, result::Result}; pub use Option::{None, Some}; diff --git a/crates/sol-types/src/types/data_type.rs b/crates/sol-types/src/types/data_type.rs index 9c1a4991a3..5989c8bfc1 100644 --- a/crates/sol-types/src/types/data_type.rs +++ b/crates/sol-types/src/types/data_type.rs @@ -14,6 +14,9 @@ use alloy_primitives::{ }; use core::{borrow::Borrow, fmt::*, hash::Hash, marker::PhantomData, ops::*}; +// IMPORTANT: Keep in sync with `rec_expand_rust_type` in +// `sol-macro/src/expand/ty.rs` + /// Bool - `bool` pub struct Bool; diff --git a/crates/sol-types/tests/sol.rs b/crates/sol-types/tests/sol.rs index bda29ecdab..15d2cbee23 100644 --- a/crates/sol-types/tests/sol.rs +++ b/crates/sol-types/tests/sol.rs @@ -1,4 +1,4 @@ -use alloy_primitives::{keccak256, Address, B256, U256}; +use alloy_primitives::{keccak256, Address, B256, I256, U256}; use alloy_sol_types::{eip712_domain, sol, SolCall, SolError, SolStruct, SolType}; use serde::Serialize; use serde_json::Value; @@ -133,15 +133,18 @@ fn function() { #[test] fn error() { sol! { - error SomeError(uint256 a); + error SomeError(int a, bool b); } - let sig = "SomeError(uint256)"; + let sig = "SomeError(int256,bool)"; assert_eq!(SomeError::SIGNATURE, sig); assert_eq!(SomeError::SELECTOR, keccak256(sig)[..4]); - let e = SomeError { a: U256::from(1) }; - assert_eq!(e.encoded_size(), 32); + let e = SomeError { + a: I256::ZERO, + b: false, + }; + assert_eq!(e.encoded_size(), 64); } // https://github.com/alloy-rs/core/issues/158 From 1de6c21841756068ad8ef45fc9fa3e28d386c8c1 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sun, 24 Sep 2023 20:21:15 +0200 Subject: [PATCH 2/4] chore: update test fixtures --- crates/sol-types/tests/ui/type.stderr | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/sol-types/tests/ui/type.stderr b/crates/sol-types/tests/ui/type.stderr index 3cdcd6374d..ce24e7200a 100644 --- a/crates/sol-types/tests/ui/type.stderr +++ b/crates/sol-types/tests/ui/type.stderr @@ -130,7 +130,7 @@ error[E0412]: cannot find type `a` in this scope 739 | mapping(mapping(a b => c d) e => mapping(f g => h i) j) map; | ^ not found in this scope -error[E0277]: the trait bound `(Address, Address, alloy_sol_types::sol_data::String, Bool, alloy_sol_types::sol_data::Bytes, alloy_sol_types::sol_data::FixedBytes<1>, alloy_sol_types::sol_data::FixedBytes<2>, alloy_sol_types::sol_data::FixedBytes<3>, alloy_sol_types::sol_data::FixedBytes<4>, alloy_sol_types::sol_data::FixedBytes<5>, alloy_sol_types::sol_data::FixedBytes<6>, alloy_sol_types::sol_data::FixedBytes<7>, alloy_sol_types::sol_data::FixedBytes<8>, alloy_sol_types::sol_data::FixedBytes<9>, alloy_sol_types::sol_data::FixedBytes<10>, alloy_sol_types::sol_data::FixedBytes<11>, alloy_sol_types::sol_data::FixedBytes<12>, alloy_sol_types::sol_data::FixedBytes<13>, alloy_sol_types::sol_data::FixedBytes<14>, alloy_sol_types::sol_data::FixedBytes<15>, alloy_sol_types::sol_data::FixedBytes<16>, alloy_sol_types::sol_data::FixedBytes<17>, alloy_sol_types::sol_data::FixedBytes<18>, alloy_sol_types::sol_data::FixedBytes<19>, alloy_sol_types::sol_data::FixedBytes<20>, alloy_sol_types::sol_data::FixedBytes<21>, alloy_sol_types::sol_data::FixedBytes<22>, alloy_sol_types::sol_data::FixedBytes<23>, alloy_sol_types::sol_data::FixedBytes<24>, alloy_sol_types::sol_data::FixedBytes<25>, alloy_sol_types::sol_data::FixedBytes<26>, alloy_sol_types::sol_data::FixedBytes<27>, alloy_sol_types::sol_data::FixedBytes<28>, alloy_sol_types::sol_data::FixedBytes<29>, alloy_sol_types::sol_data::FixedBytes<30>, alloy_sol_types::sol_data::FixedBytes<31>, alloy_sol_types::sol_data::FixedBytes<32>, Int<256>, Int<8>, Int<16>, Int<24>, Int<32>, Int<40>, Int<48>, Int<56>, Int<64>, Int<72>, Int<80>, Int<88>, Int<96>, Int<104>, Int<112>, Int<120>, Int<128>, Int<136>, Int<144>, Int<152>, Int<160>, Int<168>, Int<176>, Int<184>, Int<192>, Int<200>, Int<208>, Int<216>, Int<224>, Int<232>, Int<240>, Int<248>, Int<256>, Uint<256>, Uint<8>, Uint<16>, Uint<24>, Uint<32>, Uint<40>, Uint<48>, Uint<56>, Uint<64>, Uint<72>, Uint<80>, Uint<88>, Uint<96>, Uint<104>, Uint<112>, Uint<120>, Uint<128>, Uint<136>, Uint<144>, Uint<152>, Uint<160>, Uint<168>, Uint<176>, Uint<184>, Uint<192>, Uint<200>, Uint<208>, Uint<216>, Uint<224>, Uint<232>, Uint<240>, Uint<248>, Uint<256>): SolType` is not satisfied +error[E0277]: the trait bound `(alloy_sol_types::sol_data::Address, alloy_sol_types::sol_data::Address, alloy_sol_types::sol_data::String, Bool, alloy_sol_types::sol_data::Bytes, alloy_sol_types::sol_data::FixedBytes<1>, alloy_sol_types::sol_data::FixedBytes<2>, alloy_sol_types::sol_data::FixedBytes<3>, alloy_sol_types::sol_data::FixedBytes<4>, alloy_sol_types::sol_data::FixedBytes<5>, alloy_sol_types::sol_data::FixedBytes<6>, alloy_sol_types::sol_data::FixedBytes<7>, alloy_sol_types::sol_data::FixedBytes<8>, alloy_sol_types::sol_data::FixedBytes<9>, alloy_sol_types::sol_data::FixedBytes<10>, alloy_sol_types::sol_data::FixedBytes<11>, alloy_sol_types::sol_data::FixedBytes<12>, alloy_sol_types::sol_data::FixedBytes<13>, alloy_sol_types::sol_data::FixedBytes<14>, alloy_sol_types::sol_data::FixedBytes<15>, alloy_sol_types::sol_data::FixedBytes<16>, alloy_sol_types::sol_data::FixedBytes<17>, alloy_sol_types::sol_data::FixedBytes<18>, alloy_sol_types::sol_data::FixedBytes<19>, alloy_sol_types::sol_data::FixedBytes<20>, alloy_sol_types::sol_data::FixedBytes<21>, alloy_sol_types::sol_data::FixedBytes<22>, alloy_sol_types::sol_data::FixedBytes<23>, alloy_sol_types::sol_data::FixedBytes<24>, alloy_sol_types::sol_data::FixedBytes<25>, alloy_sol_types::sol_data::FixedBytes<26>, alloy_sol_types::sol_data::FixedBytes<27>, alloy_sol_types::sol_data::FixedBytes<28>, alloy_sol_types::sol_data::FixedBytes<29>, alloy_sol_types::sol_data::FixedBytes<30>, alloy_sol_types::sol_data::FixedBytes<31>, alloy_sol_types::sol_data::FixedBytes<32>, Int<256>, Int<8>, Int<16>, Int<24>, Int<32>, Int<40>, Int<48>, Int<56>, Int<64>, Int<72>, Int<80>, Int<88>, Int<96>, Int<104>, Int<112>, Int<120>, Int<128>, Int<136>, Int<144>, Int<152>, Int<160>, Int<168>, Int<176>, Int<184>, Int<192>, Int<200>, Int<208>, Int<216>, Int<224>, Int<232>, Int<240>, Int<248>, Int<256>, alloy_sol_types::sol_data::Uint<256>, alloy_sol_types::sol_data::Uint<8>, alloy_sol_types::sol_data::Uint<16>, alloy_sol_types::sol_data::Uint<24>, alloy_sol_types::sol_data::Uint<32>, alloy_sol_types::sol_data::Uint<40>, alloy_sol_types::sol_data::Uint<48>, alloy_sol_types::sol_data::Uint<56>, alloy_sol_types::sol_data::Uint<64>, alloy_sol_types::sol_data::Uint<72>, alloy_sol_types::sol_data::Uint<80>, alloy_sol_types::sol_data::Uint<88>, alloy_sol_types::sol_data::Uint<96>, alloy_sol_types::sol_data::Uint<104>, alloy_sol_types::sol_data::Uint<112>, alloy_sol_types::sol_data::Uint<120>, alloy_sol_types::sol_data::Uint<128>, alloy_sol_types::sol_data::Uint<136>, alloy_sol_types::sol_data::Uint<144>, alloy_sol_types::sol_data::Uint<152>, alloy_sol_types::sol_data::Uint<160>, alloy_sol_types::sol_data::Uint<168>, alloy_sol_types::sol_data::Uint<176>, alloy_sol_types::sol_data::Uint<184>, alloy_sol_types::sol_data::Uint<192>, alloy_sol_types::sol_data::Uint<200>, alloy_sol_types::sol_data::Uint<208>, alloy_sol_types::sol_data::Uint<216>, alloy_sol_types::sol_data::Uint<224>, alloy_sol_types::sol_data::Uint<232>, alloy_sol_types::sol_data::Uint<240>, alloy_sol_types::sol_data::Uint<248>, alloy_sol_types::sol_data::Uint<256>): SolType` is not satisfied --> tests/ui/type.rs:3:1 | 3 | / sol! { @@ -140,7 +140,7 @@ error[E0277]: the trait bound `(Address, Address, alloy_sol_types::sol_data::Str ... | 111 | | } 112 | | } - | |_^ the trait `SolType` is not implemented for `(Address, Address, alloy_sol_types::sol_data::String, Bool, alloy_sol_types::sol_data::Bytes, alloy_sol_types::sol_data::FixedBytes<1>, alloy_sol_types::sol_data::FixedBytes<2>, alloy_sol_types::sol_data::FixedBytes<3>, alloy_sol_types::sol_data::FixedBytes<4>, alloy_sol_types::sol_data::FixedBytes<5>, alloy_sol_types::sol_data::FixedBytes<6>, alloy_sol_types::sol_data::FixedBytes<7>, alloy_sol_types::sol_data::FixedBytes<8>, alloy_sol_types::sol_data::FixedBytes<9>, alloy_sol_types::sol_data::FixedBytes<10>, alloy_sol_types::sol_data::FixedBytes<11>, alloy_sol_types::sol_data::FixedBytes<12>, alloy_sol_types::sol_data::FixedBytes<13>, alloy_sol_types::sol_data::FixedBytes<14>, alloy_sol_types::sol_data::FixedBytes<15>, alloy_sol_types::sol_data::FixedBytes<16>, alloy_sol_types::sol_data::FixedBytes<17>, alloy_sol_types::sol_data::FixedBytes<18>, alloy_sol_types::sol_data::FixedBytes<19>, alloy_sol_types::sol_data::FixedBytes<20>, alloy_sol_types::sol_data::FixedBytes<21>, alloy_sol_types::sol_data::FixedBytes<22>, alloy_sol_types::sol_data::FixedBytes<23>, alloy_sol_types::sol_data::FixedBytes<24>, alloy_sol_types::sol_data::FixedBytes<25>, alloy_sol_types::sol_data::FixedBytes<26>, alloy_sol_types::sol_data::FixedBytes<27>, alloy_sol_types::sol_data::FixedBytes<28>, alloy_sol_types::sol_data::FixedBytes<29>, alloy_sol_types::sol_data::FixedBytes<30>, alloy_sol_types::sol_data::FixedBytes<31>, alloy_sol_types::sol_data::FixedBytes<32>, Int<256>, Int<8>, Int<16>, Int<24>, Int<32>, Int<40>, Int<48>, Int<56>, Int<64>, Int<72>, Int<80>, Int<88>, Int<96>, Int<104>, Int<112>, Int<120>, Int<128>, Int<136>, Int<144>, Int<152>, Int<160>, Int<168>, Int<176>, Int<184>, Int<192>, Int<200>, Int<208>, Int<216>, Int<224>, Int<232>, Int<240>, Int<248>, Int<256>, Uint<256>, Uint<8>, Uint<16>, Uint<24>, Uint<32>, Uint<40>, Uint<48>, Uint<56>, Uint<64>, Uint<72>, Uint<80>, Uint<88>, Uint<96>, Uint<104>, Uint<112>, Uint<120>, Uint<128>, Uint<136>, Uint<144>, Uint<152>, Uint<160>, Uint<168>, Uint<176>, Uint<184>, Uint<192>, Uint<200>, Uint<208>, Uint<216>, Uint<224>, Uint<232>, Uint<240>, Uint<248>, Uint<256>)` + | |_^ the trait `SolType` is not implemented for `(alloy_sol_types::sol_data::Address, alloy_sol_types::sol_data::Address, alloy_sol_types::sol_data::String, Bool, alloy_sol_types::sol_data::Bytes, alloy_sol_types::sol_data::FixedBytes<1>, alloy_sol_types::sol_data::FixedBytes<2>, alloy_sol_types::sol_data::FixedBytes<3>, alloy_sol_types::sol_data::FixedBytes<4>, alloy_sol_types::sol_data::FixedBytes<5>, alloy_sol_types::sol_data::FixedBytes<6>, alloy_sol_types::sol_data::FixedBytes<7>, alloy_sol_types::sol_data::FixedBytes<8>, alloy_sol_types::sol_data::FixedBytes<9>, alloy_sol_types::sol_data::FixedBytes<10>, alloy_sol_types::sol_data::FixedBytes<11>, alloy_sol_types::sol_data::FixedBytes<12>, alloy_sol_types::sol_data::FixedBytes<13>, alloy_sol_types::sol_data::FixedBytes<14>, alloy_sol_types::sol_data::FixedBytes<15>, alloy_sol_types::sol_data::FixedBytes<16>, alloy_sol_types::sol_data::FixedBytes<17>, alloy_sol_types::sol_data::FixedBytes<18>, alloy_sol_types::sol_data::FixedBytes<19>, alloy_sol_types::sol_data::FixedBytes<20>, alloy_sol_types::sol_data::FixedBytes<21>, alloy_sol_types::sol_data::FixedBytes<22>, alloy_sol_types::sol_data::FixedBytes<23>, alloy_sol_types::sol_data::FixedBytes<24>, alloy_sol_types::sol_data::FixedBytes<25>, alloy_sol_types::sol_data::FixedBytes<26>, alloy_sol_types::sol_data::FixedBytes<27>, alloy_sol_types::sol_data::FixedBytes<28>, alloy_sol_types::sol_data::FixedBytes<29>, alloy_sol_types::sol_data::FixedBytes<30>, alloy_sol_types::sol_data::FixedBytes<31>, alloy_sol_types::sol_data::FixedBytes<32>, Int<256>, Int<8>, Int<16>, Int<24>, Int<32>, Int<40>, Int<48>, Int<56>, Int<64>, Int<72>, Int<80>, Int<88>, Int<96>, Int<104>, Int<112>, Int<120>, Int<128>, Int<136>, Int<144>, Int<152>, Int<160>, Int<168>, Int<176>, Int<184>, Int<192>, Int<200>, Int<208>, Int<216>, Int<224>, Int<232>, Int<240>, Int<248>, Int<256>, alloy_sol_types::sol_data::Uint<256>, alloy_sol_types::sol_data::Uint<8>, alloy_sol_types::sol_data::Uint<16>, alloy_sol_types::sol_data::Uint<24>, alloy_sol_types::sol_data::Uint<32>, alloy_sol_types::sol_data::Uint<40>, alloy_sol_types::sol_data::Uint<48>, alloy_sol_types::sol_data::Uint<56>, alloy_sol_types::sol_data::Uint<64>, alloy_sol_types::sol_data::Uint<72>, alloy_sol_types::sol_data::Uint<80>, alloy_sol_types::sol_data::Uint<88>, alloy_sol_types::sol_data::Uint<96>, alloy_sol_types::sol_data::Uint<104>, alloy_sol_types::sol_data::Uint<112>, alloy_sol_types::sol_data::Uint<120>, alloy_sol_types::sol_data::Uint<128>, alloy_sol_types::sol_data::Uint<136>, alloy_sol_types::sol_data::Uint<144>, alloy_sol_types::sol_data::Uint<152>, alloy_sol_types::sol_data::Uint<160>, alloy_sol_types::sol_data::Uint<168>, alloy_sol_types::sol_data::Uint<176>, alloy_sol_types::sol_data::Uint<184>, alloy_sol_types::sol_data::Uint<192>, alloy_sol_types::sol_data::Uint<200>, alloy_sol_types::sol_data::Uint<208>, alloy_sol_types::sol_data::Uint<216>, alloy_sol_types::sol_data::Uint<224>, alloy_sol_types::sol_data::Uint<232>, alloy_sol_types::sol_data::Uint<240>, alloy_sol_types::sol_data::Uint<248>, alloy_sol_types::sol_data::Uint<256>)` | = help: the following other types implement trait `SolType`: () @@ -159,7 +159,7 @@ note: required by a bound in `Encodable` | ^^^^^^^ required by this bound in `Encodable` = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `(Address, Address, alloy_sol_types::sol_data::String, Bool, alloy_sol_types::sol_data::Bytes, alloy_sol_types::sol_data::FixedBytes<1>, alloy_sol_types::sol_data::FixedBytes<2>, alloy_sol_types::sol_data::FixedBytes<3>, alloy_sol_types::sol_data::FixedBytes<4>, alloy_sol_types::sol_data::FixedBytes<5>, alloy_sol_types::sol_data::FixedBytes<6>, alloy_sol_types::sol_data::FixedBytes<7>, alloy_sol_types::sol_data::FixedBytes<8>, alloy_sol_types::sol_data::FixedBytes<9>, alloy_sol_types::sol_data::FixedBytes<10>, alloy_sol_types::sol_data::FixedBytes<11>, alloy_sol_types::sol_data::FixedBytes<12>, alloy_sol_types::sol_data::FixedBytes<13>, alloy_sol_types::sol_data::FixedBytes<14>, alloy_sol_types::sol_data::FixedBytes<15>, alloy_sol_types::sol_data::FixedBytes<16>, alloy_sol_types::sol_data::FixedBytes<17>, alloy_sol_types::sol_data::FixedBytes<18>, alloy_sol_types::sol_data::FixedBytes<19>, alloy_sol_types::sol_data::FixedBytes<20>, alloy_sol_types::sol_data::FixedBytes<21>, alloy_sol_types::sol_data::FixedBytes<22>, alloy_sol_types::sol_data::FixedBytes<23>, alloy_sol_types::sol_data::FixedBytes<24>, alloy_sol_types::sol_data::FixedBytes<25>, alloy_sol_types::sol_data::FixedBytes<26>, alloy_sol_types::sol_data::FixedBytes<27>, alloy_sol_types::sol_data::FixedBytes<28>, alloy_sol_types::sol_data::FixedBytes<29>, alloy_sol_types::sol_data::FixedBytes<30>, alloy_sol_types::sol_data::FixedBytes<31>, alloy_sol_types::sol_data::FixedBytes<32>, Int<256>, Int<8>, Int<16>, Int<24>, Int<32>, Int<40>, Int<48>, Int<56>, Int<64>, Int<72>, Int<80>, Int<88>, Int<96>, Int<104>, Int<112>, Int<120>, Int<128>, Int<136>, Int<144>, Int<152>, Int<160>, Int<168>, Int<176>, Int<184>, Int<192>, Int<200>, Int<208>, Int<216>, Int<224>, Int<232>, Int<240>, Int<248>, Int<256>, Uint<256>, Uint<8>, Uint<16>, Uint<24>, Uint<32>, Uint<40>, Uint<48>, Uint<56>, Uint<64>, Uint<72>, Uint<80>, Uint<88>, Uint<96>, Uint<104>, Uint<112>, Uint<120>, Uint<128>, Uint<136>, Uint<144>, Uint<152>, Uint<160>, Uint<168>, Uint<176>, Uint<184>, Uint<192>, Uint<200>, Uint<208>, Uint<216>, Uint<224>, Uint<232>, Uint<240>, Uint<248>, Uint<256>): SolType` is not satisfied +error[E0277]: the trait bound `(alloy_sol_types::sol_data::Address, alloy_sol_types::sol_data::Address, alloy_sol_types::sol_data::String, Bool, alloy_sol_types::sol_data::Bytes, alloy_sol_types::sol_data::FixedBytes<1>, alloy_sol_types::sol_data::FixedBytes<2>, alloy_sol_types::sol_data::FixedBytes<3>, alloy_sol_types::sol_data::FixedBytes<4>, alloy_sol_types::sol_data::FixedBytes<5>, alloy_sol_types::sol_data::FixedBytes<6>, alloy_sol_types::sol_data::FixedBytes<7>, alloy_sol_types::sol_data::FixedBytes<8>, alloy_sol_types::sol_data::FixedBytes<9>, alloy_sol_types::sol_data::FixedBytes<10>, alloy_sol_types::sol_data::FixedBytes<11>, alloy_sol_types::sol_data::FixedBytes<12>, alloy_sol_types::sol_data::FixedBytes<13>, alloy_sol_types::sol_data::FixedBytes<14>, alloy_sol_types::sol_data::FixedBytes<15>, alloy_sol_types::sol_data::FixedBytes<16>, alloy_sol_types::sol_data::FixedBytes<17>, alloy_sol_types::sol_data::FixedBytes<18>, alloy_sol_types::sol_data::FixedBytes<19>, alloy_sol_types::sol_data::FixedBytes<20>, alloy_sol_types::sol_data::FixedBytes<21>, alloy_sol_types::sol_data::FixedBytes<22>, alloy_sol_types::sol_data::FixedBytes<23>, alloy_sol_types::sol_data::FixedBytes<24>, alloy_sol_types::sol_data::FixedBytes<25>, alloy_sol_types::sol_data::FixedBytes<26>, alloy_sol_types::sol_data::FixedBytes<27>, alloy_sol_types::sol_data::FixedBytes<28>, alloy_sol_types::sol_data::FixedBytes<29>, alloy_sol_types::sol_data::FixedBytes<30>, alloy_sol_types::sol_data::FixedBytes<31>, alloy_sol_types::sol_data::FixedBytes<32>, Int<256>, Int<8>, Int<16>, Int<24>, Int<32>, Int<40>, Int<48>, Int<56>, Int<64>, Int<72>, Int<80>, Int<88>, Int<96>, Int<104>, Int<112>, Int<120>, Int<128>, Int<136>, Int<144>, Int<152>, Int<160>, Int<168>, Int<176>, Int<184>, Int<192>, Int<200>, Int<208>, Int<216>, Int<224>, Int<232>, Int<240>, Int<248>, Int<256>, alloy_sol_types::sol_data::Uint<256>, alloy_sol_types::sol_data::Uint<8>, alloy_sol_types::sol_data::Uint<16>, alloy_sol_types::sol_data::Uint<24>, alloy_sol_types::sol_data::Uint<32>, alloy_sol_types::sol_data::Uint<40>, alloy_sol_types::sol_data::Uint<48>, alloy_sol_types::sol_data::Uint<56>, alloy_sol_types::sol_data::Uint<64>, alloy_sol_types::sol_data::Uint<72>, alloy_sol_types::sol_data::Uint<80>, alloy_sol_types::sol_data::Uint<88>, alloy_sol_types::sol_data::Uint<96>, alloy_sol_types::sol_data::Uint<104>, alloy_sol_types::sol_data::Uint<112>, alloy_sol_types::sol_data::Uint<120>, alloy_sol_types::sol_data::Uint<128>, alloy_sol_types::sol_data::Uint<136>, alloy_sol_types::sol_data::Uint<144>, alloy_sol_types::sol_data::Uint<152>, alloy_sol_types::sol_data::Uint<160>, alloy_sol_types::sol_data::Uint<168>, alloy_sol_types::sol_data::Uint<176>, alloy_sol_types::sol_data::Uint<184>, alloy_sol_types::sol_data::Uint<192>, alloy_sol_types::sol_data::Uint<200>, alloy_sol_types::sol_data::Uint<208>, alloy_sol_types::sol_data::Uint<216>, alloy_sol_types::sol_data::Uint<224>, alloy_sol_types::sol_data::Uint<232>, alloy_sol_types::sol_data::Uint<240>, alloy_sol_types::sol_data::Uint<248>, alloy_sol_types::sol_data::Uint<256>): SolType` is not satisfied --> tests/ui/type.rs:3:1 | 3 | / sol! { @@ -169,7 +169,7 @@ error[E0277]: the trait bound `(Address, Address, alloy_sol_types::sol_data::Str ... | 111 | | } 112 | | } - | |_^ the trait `SolType` is not implemented for `(Address, Address, alloy_sol_types::sol_data::String, Bool, alloy_sol_types::sol_data::Bytes, alloy_sol_types::sol_data::FixedBytes<1>, alloy_sol_types::sol_data::FixedBytes<2>, alloy_sol_types::sol_data::FixedBytes<3>, alloy_sol_types::sol_data::FixedBytes<4>, alloy_sol_types::sol_data::FixedBytes<5>, alloy_sol_types::sol_data::FixedBytes<6>, alloy_sol_types::sol_data::FixedBytes<7>, alloy_sol_types::sol_data::FixedBytes<8>, alloy_sol_types::sol_data::FixedBytes<9>, alloy_sol_types::sol_data::FixedBytes<10>, alloy_sol_types::sol_data::FixedBytes<11>, alloy_sol_types::sol_data::FixedBytes<12>, alloy_sol_types::sol_data::FixedBytes<13>, alloy_sol_types::sol_data::FixedBytes<14>, alloy_sol_types::sol_data::FixedBytes<15>, alloy_sol_types::sol_data::FixedBytes<16>, alloy_sol_types::sol_data::FixedBytes<17>, alloy_sol_types::sol_data::FixedBytes<18>, alloy_sol_types::sol_data::FixedBytes<19>, alloy_sol_types::sol_data::FixedBytes<20>, alloy_sol_types::sol_data::FixedBytes<21>, alloy_sol_types::sol_data::FixedBytes<22>, alloy_sol_types::sol_data::FixedBytes<23>, alloy_sol_types::sol_data::FixedBytes<24>, alloy_sol_types::sol_data::FixedBytes<25>, alloy_sol_types::sol_data::FixedBytes<26>, alloy_sol_types::sol_data::FixedBytes<27>, alloy_sol_types::sol_data::FixedBytes<28>, alloy_sol_types::sol_data::FixedBytes<29>, alloy_sol_types::sol_data::FixedBytes<30>, alloy_sol_types::sol_data::FixedBytes<31>, alloy_sol_types::sol_data::FixedBytes<32>, Int<256>, Int<8>, Int<16>, Int<24>, Int<32>, Int<40>, Int<48>, Int<56>, Int<64>, Int<72>, Int<80>, Int<88>, Int<96>, Int<104>, Int<112>, Int<120>, Int<128>, Int<136>, Int<144>, Int<152>, Int<160>, Int<168>, Int<176>, Int<184>, Int<192>, Int<200>, Int<208>, Int<216>, Int<224>, Int<232>, Int<240>, Int<248>, Int<256>, Uint<256>, Uint<8>, Uint<16>, Uint<24>, Uint<32>, Uint<40>, Uint<48>, Uint<56>, Uint<64>, Uint<72>, Uint<80>, Uint<88>, Uint<96>, Uint<104>, Uint<112>, Uint<120>, Uint<128>, Uint<136>, Uint<144>, Uint<152>, Uint<160>, Uint<168>, Uint<176>, Uint<184>, Uint<192>, Uint<200>, Uint<208>, Uint<216>, Uint<224>, Uint<232>, Uint<240>, Uint<248>, Uint<256>)` + | |_^ the trait `SolType` is not implemented for `(alloy_sol_types::sol_data::Address, alloy_sol_types::sol_data::Address, alloy_sol_types::sol_data::String, Bool, alloy_sol_types::sol_data::Bytes, alloy_sol_types::sol_data::FixedBytes<1>, alloy_sol_types::sol_data::FixedBytes<2>, alloy_sol_types::sol_data::FixedBytes<3>, alloy_sol_types::sol_data::FixedBytes<4>, alloy_sol_types::sol_data::FixedBytes<5>, alloy_sol_types::sol_data::FixedBytes<6>, alloy_sol_types::sol_data::FixedBytes<7>, alloy_sol_types::sol_data::FixedBytes<8>, alloy_sol_types::sol_data::FixedBytes<9>, alloy_sol_types::sol_data::FixedBytes<10>, alloy_sol_types::sol_data::FixedBytes<11>, alloy_sol_types::sol_data::FixedBytes<12>, alloy_sol_types::sol_data::FixedBytes<13>, alloy_sol_types::sol_data::FixedBytes<14>, alloy_sol_types::sol_data::FixedBytes<15>, alloy_sol_types::sol_data::FixedBytes<16>, alloy_sol_types::sol_data::FixedBytes<17>, alloy_sol_types::sol_data::FixedBytes<18>, alloy_sol_types::sol_data::FixedBytes<19>, alloy_sol_types::sol_data::FixedBytes<20>, alloy_sol_types::sol_data::FixedBytes<21>, alloy_sol_types::sol_data::FixedBytes<22>, alloy_sol_types::sol_data::FixedBytes<23>, alloy_sol_types::sol_data::FixedBytes<24>, alloy_sol_types::sol_data::FixedBytes<25>, alloy_sol_types::sol_data::FixedBytes<26>, alloy_sol_types::sol_data::FixedBytes<27>, alloy_sol_types::sol_data::FixedBytes<28>, alloy_sol_types::sol_data::FixedBytes<29>, alloy_sol_types::sol_data::FixedBytes<30>, alloy_sol_types::sol_data::FixedBytes<31>, alloy_sol_types::sol_data::FixedBytes<32>, Int<256>, Int<8>, Int<16>, Int<24>, Int<32>, Int<40>, Int<48>, Int<56>, Int<64>, Int<72>, Int<80>, Int<88>, Int<96>, Int<104>, Int<112>, Int<120>, Int<128>, Int<136>, Int<144>, Int<152>, Int<160>, Int<168>, Int<176>, Int<184>, Int<192>, Int<200>, Int<208>, Int<216>, Int<224>, Int<232>, Int<240>, Int<248>, Int<256>, alloy_sol_types::sol_data::Uint<256>, alloy_sol_types::sol_data::Uint<8>, alloy_sol_types::sol_data::Uint<16>, alloy_sol_types::sol_data::Uint<24>, alloy_sol_types::sol_data::Uint<32>, alloy_sol_types::sol_data::Uint<40>, alloy_sol_types::sol_data::Uint<48>, alloy_sol_types::sol_data::Uint<56>, alloy_sol_types::sol_data::Uint<64>, alloy_sol_types::sol_data::Uint<72>, alloy_sol_types::sol_data::Uint<80>, alloy_sol_types::sol_data::Uint<88>, alloy_sol_types::sol_data::Uint<96>, alloy_sol_types::sol_data::Uint<104>, alloy_sol_types::sol_data::Uint<112>, alloy_sol_types::sol_data::Uint<120>, alloy_sol_types::sol_data::Uint<128>, alloy_sol_types::sol_data::Uint<136>, alloy_sol_types::sol_data::Uint<144>, alloy_sol_types::sol_data::Uint<152>, alloy_sol_types::sol_data::Uint<160>, alloy_sol_types::sol_data::Uint<168>, alloy_sol_types::sol_data::Uint<176>, alloy_sol_types::sol_data::Uint<184>, alloy_sol_types::sol_data::Uint<192>, alloy_sol_types::sol_data::Uint<200>, alloy_sol_types::sol_data::Uint<208>, alloy_sol_types::sol_data::Uint<216>, alloy_sol_types::sol_data::Uint<224>, alloy_sol_types::sol_data::Uint<232>, alloy_sol_types::sol_data::Uint<240>, alloy_sol_types::sol_data::Uint<248>, alloy_sol_types::sol_data::Uint<256>)` | = help: the following other types implement trait `SolType`: () From 1241a9096e14d40259f902cd7d347b7d990eaa3a Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sun, 24 Sep 2023 20:52:09 +0200 Subject: [PATCH 3/4] chore: unremove spans --- crates/sol-macro/src/expand/event.rs | 23 +++-- crates/sol-macro/src/expand/mod.rs | 11 +-- crates/sol-macro/src/expand/struct.rs | 6 +- crates/sol-types/tests/ui/type.stderr | 116 ++++++++++++++++++++++++++ 4 files changed, 133 insertions(+), 23 deletions(-) diff --git a/crates/sol-macro/src/expand/event.rs b/crates/sol-macro/src/expand/event.rs index f6ced717f4..dd6044891d 100644 --- a/crates/sol-macro/src/expand/event.rs +++ b/crates/sol-macro/src/expand/event.rs @@ -1,7 +1,6 @@ //! [`ItemEvent`] expansion. -use super::{anon_name, expand_tuple_types, expand_type, ExpCtxt}; -use crate::expand::ty::expand_event_tokenize_func; +use super::{anon_name, expand_tuple_types, expand_type, ty, ExpCtxt}; use ast::{EventParameter, ItemEvent, SolIdent, Spanned}; use proc_macro2::TokenStream; use quote::{quote, quote_spanned}; @@ -93,7 +92,7 @@ pub(super) fn expand(cx: &ExpCtxt<'_>, event: &ItemEvent) -> Result .enumerate() .map(|(i, p)| expand_event_topic_field(i, p, p.name.as_ref())); - let tokenize_body_impl = expand_event_tokenize_func(event.parameters.iter()); + let tokenize_body_impl = ty::expand_event_tokenize_func(event.parameters.iter()); let encode_topics_impl = encode_first_topic .into_iter() @@ -176,15 +175,13 @@ fn expand_event_topic_field( name: Option<&SolIdent>, ) -> TokenStream { let name = anon_name((i, name)); - - if param.indexed_as_hash() { - quote! { - #name: <::alloy_sol_types::sol_data::FixedBytes<32> as ::alloy_sol_types::SolType>::RustType - } + let ty = if param.indexed_as_hash() { + ty::expand_rust_type(&ast::Type::FixedBytes( + name.span(), + core::num::NonZeroU16::new(32).unwrap(), + )) } else { - let ty = expand_type(¶m.ty); - quote! { - #name: <#ty as ::alloy_sol_types::SolType>::RustType - } - } + ty::expand_rust_type(¶m.ty) + }; + quote!(#name: #ty) } diff --git a/crates/sol-macro/src/expand/mod.rs b/crates/sol-macro/src/expand/mod.rs index f06452561e..375aa06c72 100644 --- a/crates/sol-macro/src/expand/mod.rs +++ b/crates/sol-macro/src/expand/mod.rs @@ -506,9 +506,7 @@ fn expand_from_into_tuples

(name: &Ident, fields: &Parameters

) -> TokenStre } } -/// Returns -/// - `(#(#expanded,)*)` -/// - `(#(<#expanded as ::alloy_sol_types::SolType>::RustType,)*)` +/// Returns `(sol_tuple, rust_tuple)` fn expand_tuple_types<'a, I: IntoIterator>( types: I, ) -> (TokenStream, TokenStream) { @@ -522,8 +520,7 @@ fn expand_tuple_types<'a, I: IntoIterator>( ty::rec_expand_rust_type(ty, &mut rust); rust.append(comma.clone()); } - ( - TokenStream::from(TokenTree::Group(Group::new(Delimiter::Parenthesis, sol))), - TokenStream::from(TokenTree::Group(Group::new(Delimiter::Parenthesis, rust))), - ) + let wrap_in_parens = + |stream| TokenStream::from(TokenTree::Group(Group::new(Delimiter::Parenthesis, stream))); + (wrap_in_parens(sol), wrap_in_parens(rust)) } diff --git a/crates/sol-macro/src/expand/struct.rs b/crates/sol-macro/src/expand/struct.rs index b1c64eb199..ff298288e2 100644 --- a/crates/sol-macro/src/expand/struct.rs +++ b/crates/sol-macro/src/expand/struct.rs @@ -3,7 +3,7 @@ use super::{ expand_fields, expand_from_into_tuples, expand_type, ty::expand_tokenize_func, ExpCtxt, }; -use ast::{Item, ItemStruct, Spanned, Type, VariableDeclaration}; +use ast::{Item, ItemStruct, Spanned, Type}; use proc_macro2::TokenStream; use quote::quote; use std::num::NonZeroU16; @@ -48,8 +48,8 @@ pub(super) fn expand(cx: &ExpCtxt<'_>, s: &ItemStruct) -> Result { let encode_data_impl = match fields.len() { 0 => unreachable!("struct with zero fields"), 1 => { - let VariableDeclaration { ty, name, .. } = fields.first().unwrap(); - let ty = expand_type(ty); + let name = *field_names.first().unwrap(); + let ty = field_types.first().unwrap(); quote!(<#ty as ::alloy_sol_types::SolType>::eip712_data_word(&self.#name).0.to_vec()) } _ => quote! { diff --git a/crates/sol-types/tests/ui/type.stderr b/crates/sol-types/tests/ui/type.stderr index ce24e7200a..6bae6044a4 100644 --- a/crates/sol-types/tests/ui/type.stderr +++ b/crates/sol-types/tests/ui/type.stderr @@ -70,12 +70,34 @@ error: Mapping types are not supported here 739 | mapping(mapping(a b => c d) e => mapping(f g => h i) j) map; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +error: Mapping types are not supported here + --> tests/ui/type.rs:737:1 + | +737 | / sol! { +738 | | struct Mappings { +739 | | mapping(mapping(a b => c d) e => mapping(f g => h i) j) map; +740 | | } +741 | | } + | |_^ + | + = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) + error: Mapping types are not supported here --> tests/ui/type.rs:748:13 | 748 | mapping(mapping(int => int) => int) public mapKeyOfMap; | ^^^^^^^^^^^^^^^^^^^ +error: Mapping types are not supported here + --> tests/ui/type.rs:747:1 + | +747 | / sol! { +748 | | mapping(mapping(int => int) => int) public mapKeyOfMap; +749 | | } + | |_^ + | + = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) + error: Mapping types are not supported here --> tests/ui/type.rs:752:23 | @@ -88,6 +110,16 @@ error: Mapping types are not supported here 752 | function mappings(mapping(uint256 a => bool b), mapping(bool => bool) x); | ^^^^^^^^^^^^^^^^^^^^^ +error: Mapping types are not supported here + --> tests/ui/type.rs:751:1 + | +751 | / sol! { +752 | | function mappings(mapping(uint256 a => bool b), mapping(bool => bool) x); +753 | | } + | |_^ + | + = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) + error[E0412]: cannot find type `bytes_` in this scope --> tests/ui/type.rs:205:9 | @@ -124,6 +156,90 @@ error[E0412]: cannot find type `int_256` in this scope 210 | int_256 f; | ^^^^^^^ not found in this scope +error[E0412]: cannot find type `bytes_` in this scope + --> tests/ui/type.rs:203:1 + | +203 | / sol! { +204 | | struct CustomTypes { +205 | | bytes_ a; +206 | | bytes_32 b; +... | +211 | | } +212 | | } + | |_^ not found in this scope + | + = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0412]: cannot find type `bytes_32` in this scope + --> tests/ui/type.rs:203:1 + | +203 | / sol! { +204 | | struct CustomTypes { +205 | | bytes_ a; +206 | | bytes_32 b; +... | +211 | | } +212 | | } + | |_^ not found in this scope + | + = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0412]: cannot find type `uint_` in this scope + --> tests/ui/type.rs:203:1 + | +203 | / sol! { +204 | | struct CustomTypes { +205 | | bytes_ a; +206 | | bytes_32 b; +... | +211 | | } +212 | | } + | |_^ not found in this scope + | + = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0412]: cannot find type `uint_256` in this scope + --> tests/ui/type.rs:203:1 + | +203 | / sol! { +204 | | struct CustomTypes { +205 | | bytes_ a; +206 | | bytes_32 b; +... | +211 | | } +212 | | } + | |_^ not found in this scope + | + = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0412]: cannot find type `int_` in this scope + --> tests/ui/type.rs:203:1 + | +203 | / sol! { +204 | | struct CustomTypes { +205 | | bytes_ a; +206 | | bytes_32 b; +... | +211 | | } +212 | | } + | |_^ not found in this scope + | + = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0412]: cannot find type `int_256` in this scope + --> tests/ui/type.rs:203:1 + | +203 | / sol! { +204 | | struct CustomTypes { +205 | | bytes_ a; +206 | | bytes_32 b; +... | +211 | | } +212 | | } + | |_^ not found in this scope + | + = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) + error[E0412]: cannot find type `a` in this scope --> tests/ui/type.rs:739:25 | From 571f52fd36d314f58d7d045f58a255701badada3 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sun, 24 Sep 2023 23:46:19 +0200 Subject: [PATCH 4/4] bless --- crates/sol-types/tests/ui/type.stderr | 116 -------------------------- 1 file changed, 116 deletions(-) diff --git a/crates/sol-types/tests/ui/type.stderr b/crates/sol-types/tests/ui/type.stderr index 6bae6044a4..ce24e7200a 100644 --- a/crates/sol-types/tests/ui/type.stderr +++ b/crates/sol-types/tests/ui/type.stderr @@ -70,34 +70,12 @@ error: Mapping types are not supported here 739 | mapping(mapping(a b => c d) e => mapping(f g => h i) j) map; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: Mapping types are not supported here - --> tests/ui/type.rs:737:1 - | -737 | / sol! { -738 | | struct Mappings { -739 | | mapping(mapping(a b => c d) e => mapping(f g => h i) j) map; -740 | | } -741 | | } - | |_^ - | - = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) - error: Mapping types are not supported here --> tests/ui/type.rs:748:13 | 748 | mapping(mapping(int => int) => int) public mapKeyOfMap; | ^^^^^^^^^^^^^^^^^^^ -error: Mapping types are not supported here - --> tests/ui/type.rs:747:1 - | -747 | / sol! { -748 | | mapping(mapping(int => int) => int) public mapKeyOfMap; -749 | | } - | |_^ - | - = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) - error: Mapping types are not supported here --> tests/ui/type.rs:752:23 | @@ -110,16 +88,6 @@ error: Mapping types are not supported here 752 | function mappings(mapping(uint256 a => bool b), mapping(bool => bool) x); | ^^^^^^^^^^^^^^^^^^^^^ -error: Mapping types are not supported here - --> tests/ui/type.rs:751:1 - | -751 | / sol! { -752 | | function mappings(mapping(uint256 a => bool b), mapping(bool => bool) x); -753 | | } - | |_^ - | - = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) - error[E0412]: cannot find type `bytes_` in this scope --> tests/ui/type.rs:205:9 | @@ -156,90 +124,6 @@ error[E0412]: cannot find type `int_256` in this scope 210 | int_256 f; | ^^^^^^^ not found in this scope -error[E0412]: cannot find type `bytes_` in this scope - --> tests/ui/type.rs:203:1 - | -203 | / sol! { -204 | | struct CustomTypes { -205 | | bytes_ a; -206 | | bytes_32 b; -... | -211 | | } -212 | | } - | |_^ not found in this scope - | - = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0412]: cannot find type `bytes_32` in this scope - --> tests/ui/type.rs:203:1 - | -203 | / sol! { -204 | | struct CustomTypes { -205 | | bytes_ a; -206 | | bytes_32 b; -... | -211 | | } -212 | | } - | |_^ not found in this scope - | - = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0412]: cannot find type `uint_` in this scope - --> tests/ui/type.rs:203:1 - | -203 | / sol! { -204 | | struct CustomTypes { -205 | | bytes_ a; -206 | | bytes_32 b; -... | -211 | | } -212 | | } - | |_^ not found in this scope - | - = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0412]: cannot find type `uint_256` in this scope - --> tests/ui/type.rs:203:1 - | -203 | / sol! { -204 | | struct CustomTypes { -205 | | bytes_ a; -206 | | bytes_32 b; -... | -211 | | } -212 | | } - | |_^ not found in this scope - | - = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0412]: cannot find type `int_` in this scope - --> tests/ui/type.rs:203:1 - | -203 | / sol! { -204 | | struct CustomTypes { -205 | | bytes_ a; -206 | | bytes_32 b; -... | -211 | | } -212 | | } - | |_^ not found in this scope - | - = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0412]: cannot find type `int_256` in this scope - --> tests/ui/type.rs:203:1 - | -203 | / sol! { -204 | | struct CustomTypes { -205 | | bytes_ a; -206 | | bytes_32 b; -... | -211 | | } -212 | | } - | |_^ not found in this scope - | - = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) - error[E0412]: cannot find type `a` in this scope --> tests/ui/type.rs:739:25 |