diff --git a/abi/sol-type-parser/src/common/variable.rs b/abi/sol-type-parser/src/common/variable.rs index ac0df176e0..1db143c3c4 100644 --- a/abi/sol-type-parser/src/common/variable.rs +++ b/abi/sol-type-parser/src/common/variable.rs @@ -58,7 +58,9 @@ impl Parse for Parameters { impl Parse for Parameters { fn parse(input: ParseStream) -> Result { let this = input.parse_terminated(VariableDeclaration::parse_for_struct, Token![;])?; - if !this.is_empty() && !this.trailing_punct() { + if this.is_empty() { + Err(input.error("defining empty structs is disallowed")) + } else if !this.trailing_punct() { Err(input.error("expected trailing semicolon")) } else { Ok(Self(this)) diff --git a/abi/sol-type-parser/src/struct.rs b/abi/sol-type-parser/src/struct.rs index fbc0e0df42..abe4ba34ac 100644 --- a/abi/sol-type-parser/src/struct.rs +++ b/abi/sol-type-parser/src/struct.rs @@ -3,7 +3,7 @@ use crate::{ r#type::Type, }; use proc_macro2::TokenStream; -use quote::{quote, quote_spanned}; +use quote::quote; use std::fmt; use syn::{ braced, @@ -75,7 +75,7 @@ impl Struct { }; let encode_data_impl = match self.fields.len() { - 0 => quote! { vec![] }, + 0 => unreachable!(), 1 => { let VariableDeclaration { ty, name, .. } = self.fields.first().unwrap(); quote!(<#ty as ::ethers_abi_enc::SolDataType>::eip712_data_word(&self.#name).0.to_vec()) @@ -136,11 +136,6 @@ impl Struct { } pub fn to_tokens(&self, tokens: &mut TokenStream, attrs: &[Attribute]) { - if self.fields.is_empty() { - tokens.extend(quote_spanned! {self.name.span()=> - compile_error!("defining empty structs is disallowed."); - }); - } tokens.extend(self.expand_impl(attrs)) } diff --git a/abi/tests/ui/empty.stderr b/abi/tests/ui/empty.stderr index 32a885226b..31d3ff7565 100644 --- a/abi/tests/ui/empty.stderr +++ b/abi/tests/ui/empty.stderr @@ -6,8 +6,8 @@ error: unexpected end of input, expected at least one of: `type`, `struct`, `fun | = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info) -error: defining empty structs is disallowed. - --> tests/ui/empty.rs:6:12 +error: unexpected end of input, defining empty structs is disallowed + --> tests/ui/empty.rs:6:25 | 6 | struct EmptyStruct {} - | ^^^^^^^^^^^ + | ^