Skip to content

Commit

Permalink
fix functions in non-self module
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Apr 30, 2024
1 parent 823b7fc commit 9a3f807
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
19 changes: 8 additions & 11 deletions macros/src/specta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,11 @@ pub fn attribute(item: proc_macro::TokenStream) -> syn::Result<proc_macro::Token
}

let visibility = &function.vis;
let (maybe_macro_export, pub_the_trait) = match &visibility {
Visibility::Public(_) => (quote!(#[macro_export]), Default::default()),
_ => (
Default::default(),
quote! {
// allow the macro to be resolved with the same path as the function
#[allow(unused_imports)]
#visibility use #wrapper;
},
),
let maybe_macro_export = match &visibility {
Visibility::Public(_) => {
quote!(#[macro_export])
}
_ => Default::default(),
};

let function_name = &function.sig.ident;
Expand Down Expand Up @@ -91,7 +86,9 @@ pub fn attribute(item: proc_macro::TokenStream) -> syn::Result<proc_macro::Token
}
}

#pub_the_trait
// allow the macro to be resolved with the same path as the function
#[allow(unused_imports)]
#visibility use #wrapper;
}
.into())
}
2 changes: 1 addition & 1 deletion src/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ macro_rules! collect_functions {
let mut type_map: $crate::TypeMap = $type_map;
([$($crate::fn_datatype!(type_map; $command)),*]
.into_iter()
.collect::<Vec<_>>(), type_map)
.collect::<Vec<$crate::function::FunctionDataType>>(), type_map)
}};
($($command:path),* $(,)?) => {{
let mut type_map = $crate::TypeMap::default();
Expand Down
10 changes: 9 additions & 1 deletion tests/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ mod test {
#[specta]
pub fn public_function() {}

mod nested {
use super::*;

#[specta]
pub fn nested() {}
}

// TODO: Finish fixing these

#[test]
Expand All @@ -92,7 +99,8 @@ mod test {
function::collect_functions![a, b, c];
function::collect_functions![a, b, c,];

let (functions, types) = function::collect_functions![a, b, c, d, e::<i32>, f, g, h, i, k];
let (functions, types) =
function::collect_functions![a, b, c, d, e::<i32>, f, g, h, i, k, nested::nested];
}

#[test]
Expand Down

0 comments on commit 9a3f807

Please sign in to comment.