@@ -3,8 +3,8 @@ use proc_macro2::{Span, TokenStream as TokenStream2};
3
3
use proc_macro_error:: { proc_macro_error, SpanRange } ;
4
4
use quote:: { quote, ToTokens } ;
5
5
use syn:: {
6
- parse_macro_input, punctuated:: Punctuated , Attribute , AttributeArgs , DeriveInput , FnArg , Ident ,
7
- Item , ItemFn , Signature , Token ,
6
+ parse_macro_input, parse_quote , punctuated:: Punctuated , Attribute , AttributeArgs , DeriveInput ,
7
+ FnArg , Ident , Item , ItemFn , Signature , Token ,
8
8
} ;
9
9
10
10
// https://git.picodata.io/picodata/picodata/tarantool-module/-/merge_requests/505#note_78473
@@ -17,6 +17,10 @@ macro_rules! unwrap_or_compile_error {
17
17
} ;
18
18
}
19
19
20
+ fn default_tarantool_crate_path ( ) -> syn:: Path {
21
+ parse_quote ! { tarantool }
22
+ }
23
+
20
24
mod test;
21
25
22
26
/// Mark a function as a test.
@@ -842,8 +846,13 @@ pub fn derive_encode(input: TokenStream) -> TokenStream {
842
846
843
847
// Get attribute arguments
844
848
let args: msgpack:: Args = darling:: FromDeriveInput :: from_derive_input ( & input) . unwrap ( ) ;
845
- let tarantool_crate = args. tarantool . as_deref ( ) . unwrap_or ( "tarantool" ) ;
846
- let tarantool_crate = Ident :: new ( tarantool_crate, Span :: call_site ( ) ) . into ( ) ;
849
+ let tarantool_crate = args
850
+ . tarantool
851
+ . as_deref ( )
852
+ . map ( syn:: parse_str)
853
+ . transpose ( )
854
+ . unwrap ( )
855
+ . unwrap_or_else ( default_tarantool_crate_path) ;
847
856
848
857
// Add a bound to every type parameter.
849
858
let generics = msgpack:: add_trait_bounds ( input. generics , & tarantool_crate) ;
@@ -1049,7 +1058,7 @@ struct Context {
1049
1058
1050
1059
impl Context {
1051
1060
fn from_args ( args : AttributeArgs ) -> Self {
1052
- let mut tarantool: syn:: Path = syn :: parse2 ( quote ! { :: tarantool } ) . unwrap ( ) ;
1061
+ let mut tarantool: syn:: Path = default_tarantool_crate_path ( ) ;
1053
1062
let mut linkme = None ;
1054
1063
let mut section = None ;
1055
1064
let mut debug_tuple_needed = false ;
0 commit comments