1- use anyhow:: { anyhow, Result } ;
21use proc_macro2:: TokenStream ;
32use quote:: quote;
3+ use syn:: { spanned:: Spanned , Result } ;
44
55use super :: common:: { get_idl_module_path, get_no_docs} ;
66use crate :: parser:: docs;
@@ -22,7 +22,7 @@ pub fn impl_idl_build_union(item: &syn::ItemUnion) -> TokenStream {
2222 impl_idl_build (
2323 & item. ident ,
2424 & item. generics ,
25- Err ( anyhow ! ( "Unions are not supported" ) ) ,
25+ Err ( syn :: Error :: new_spanned ( item , "Unions are not supported" ) ) ,
2626 )
2727}
2828
@@ -33,10 +33,11 @@ fn impl_idl_build(
3333 type_def : Result < ( TokenStream , Vec < syn:: TypePath > ) > ,
3434) -> TokenStream {
3535 let idl = get_idl_module_path ( ) ;
36- let ( impl_generics, ty_generics, where_clause) = generics. split_for_impl ( ) ;
3736 let idl_build_trait = quote ! ( anchor_lang:: idl:: build:: IdlBuild ) ;
37+ let ( impl_generics, ty_generics, where_clause) = generics. split_for_impl ( ) ;
3838
3939 let ( idl_type_def, insert_defined) = match type_def {
40+ Err ( e) => return e. into_compile_error ( ) ,
4041 Ok ( ( ts, defined) ) => (
4142 quote ! { Some ( #ts) } ,
4243 quote ! {
@@ -48,7 +49,6 @@ fn impl_idl_build(
4849 ) ; *
4950 } ,
5051 ) ,
51- _ => ( quote ! { None } , quote ! { } ) ,
5252 } ;
5353
5454 quote ! {
@@ -612,7 +612,12 @@ pub fn gen_idl_type(
612612 defined. extend ( def) ;
613613 quote ! { #idl:: IdlGenericArg :: Type { ty: #ty } }
614614 }
615- _ => return Err ( anyhow ! ( "Unsupported generic argument: {arg:#?}" ) ) ,
615+ _ => {
616+ return Err ( syn:: Error :: new (
617+ arg. span ( ) ,
618+ "Unsupported generic argument" ,
619+ ) )
620+ }
616621 } ;
617622 generics. push ( generic) ;
618623 }
@@ -635,7 +640,7 @@ pub fn gen_idl_type(
635640 }
636641 _ => gen_idl_type ( & reference. elem , generic_params) ,
637642 } ,
638- _ => Err ( anyhow ! ( "Unknown type: {ty:#?} ") ) ,
643+ _ => Err ( syn :: Error :: new_spanned ( ty , "Unsupported type") ) ,
639644 }
640645}
641646
0 commit comments