Skip to content

Commit

Permalink
Attempt to handle references from macro_rules #30
Browse files Browse the repository at this point in the history
  • Loading branch information
dcchut authored Sep 2, 2023
1 parent 41aae56 commit 833b021
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,18 @@ fn transform_sig(sig: &mut Signature, args: &RecursionArgs) {

for arg in &mut sig.inputs {
if let FnArg::Typed(pt) = arg {
if let Type::Reference(tr) = pt.ty.as_mut() {
ref_arguments.push(tr);
match pt.ty.as_mut() {
// rustc can give us a None-delimited group if this type comes from
// a macro_rules macro. I don't this can happen for code the user has written.
Type::Group(tg) => {
if let Type::Reference(tr) = &mut *tg.elem {
ref_arguments.push(tr);
}
}
Type::Reference(tr) => {
ref_arguments.push(tr);
}
_ => {}
}
} else if let FnArg::Receiver(recv) = arg {
if let Some((_, slt)) = &mut recv.reference {
Expand Down
26 changes: 26 additions & 0 deletions tests/macros_all_the_way_down.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use futures_executor::block_on;

macro_rules! recurse {
($name:ident, $param:ty) => {
#[::async_recursion::async_recursion]
async fn $name<F>(param: $param, f: &F)
where
F: Fn($param) + Sync + Send,
{
f(param);
}
};
}

recurse!(owned, usize);
recurse!(by_ref, &usize);
recurse!(by_ref_mut, &mut usize);

#[test]
fn async_in_macro() {
block_on(async move {
owned(5, &|_| ()).await;
by_ref(&5, &|_| ()).await;
by_ref_mut(&mut 5, &|_| ()).await;
});
}

0 comments on commit 833b021

Please sign in to comment.