File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed
Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change 1515use super :: blake2:: blake2b_256;
1616use crate :: literal:: HexLiteral ;
1717use proc_macro2:: TokenStream as TokenStream2 ;
18+ use quote:: ToTokens ;
1819use std:: marker:: PhantomData ;
1920use syn:: {
2021 parse:: Parser ,
@@ -270,13 +271,25 @@ impl<T> TryFrom<TokenStream2> for SelectorMacro<T> {
270271 } ;
271272
272273 // Parse the literal (second argument)
274+ // We need to handle both direct literals and literals passed through declarative
275+ // macros. When a literal is captured by a declarative macro and passed through,
276+ // it may not be recognized as syn::Expr::Lit. In such cases, we try to parse
277+ // the expression's token stream directly as a literal.
273278 let lit = match & exprs[ 1 ] {
274279 syn:: Expr :: Lit ( expr_lit) => expr_lit. lit . clone ( ) ,
275- invalid => {
276- return Err ( format_err ! (
277- invalid. span( ) ,
278- "expected string or byte string literal as second argument" ,
279- ) )
280+ other_expr => {
281+ // Try to parse the expression's tokens directly as a literal
282+ // This handles cases where literals are passed through declarative macros
283+ let tokens = other_expr. to_token_stream ( ) ;
284+ match syn:: parse2 :: < syn:: Lit > ( tokens) {
285+ Ok ( lit) => lit,
286+ Err ( _) => {
287+ return Err ( format_err ! (
288+ other_expr. span( ) ,
289+ "expected string or byte string literal as second argument" ,
290+ ) )
291+ }
292+ }
280293 }
281294 } ;
282295
Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ pub use self::{
7171 Namespace ,
7272 Receiver ,
7373 Selector ,
74+ SelectorAbi ,
7475 SelectorMacro ,
7576 SignatureTopic ,
7677 Storage ,
You can’t perform that action at this time.
0 commit comments